Bug in list comprehensions?

Fredrik Lundh fredrik at pythonware.com
Wed Jun 7 06:39:24 EDT 2006


Iain King wrote:

> I'm guessing I'm the one confused here... but I'm confused!  What's 
> going on?

reading the documentation may help:

     /.../ the elements of the new list are those that would be produced
     by considering each of the for or if clauses a block, nesting from left
     to right, and evaluating the expression to produce a list element each
     time the innermost block is reached.

the clauses nest from left to right, not from right to left, so "[x for 
x in y for y in beta]" is equivalent to

      out = []
      for x in y:
          for y in beta:
              out.append(x)

</F>




More information about the Python-list mailing list