Take the 2-minute tour ×  In Python you can have multiple
iterators in a list comprehension, like  [(x,y) for x in a for y
in b]  for some suitable sequences a and b. I'm aware of the
nested loop semantics of Python's list comprehensions.  My
question is: Can one iterator in the comprehension refer to the
other? In other words: Could I have something like this:  [x for
x in a for a in b]  where the current value of the outer loop is
the iterator of the inner?  As an example, if I have a nested
list:   what would the list comprehension expression be to
achieve this result:   ?? (Please only list comprehension
answers, since this is what I want to find out).  share|improve
this question  2 Answers 2  To answer your question with your
own suggestion:  >>> [x for b in a for x in b] # Works fine
While you asked for list comprehension answers, let me also
point out the excellent itertools.chain():  >>> from itertools
import chain >>> list(chain.from_iterable(a)) >>>
list(chain(*a)) # If you're using python < 2.6 s