title: Recursion with ternary operator 'hack' in Python
body: <p>Playing around in Python, I found that the following code works as I expected:</p>
  
  <pre><code>f = lambda S,b : (S if len(S)==b else f(S[1:],b))
  </code></pre>
  
  <p>From a list S, it will recursively drop the first element until the length of S equals b. For instance f([1,2,3,4,5,6],3) = [4,5,6].</p>
  
  <p>However, much to my surprise the following solution, that uses the 'ternary hack' [a,b][c] instead of "b if c else a" (aka "c?b:a") does not work:</p>
  
  <pre><code>g = lambda S,b : (g(S[1:],b),S)[len(S)==b]
  </code></pre>
  
  <p>This will exceed maximum recursion depth.</p>
  
  <p>Why doesn't this work?</p>
  
  <p>(I know neither is an example of great coding style but that is beside the point now.)</p>