simultaneous assignment
John Salerno
johnjsal at NOSPAMgmail.com
Tue May 2 15:50:35 EDT 2006
Steve R. Hastings wrote:
> We could also use "generator expressions", available only in
> Python 2.4 and newer.
>
> A list comprehension always builds a list. A generator expression can
> return values one at a time.
>
> [v for v in seq if v] # builds a list and returns it
> (v for v in seq if v) # returns a generator object
Woah, interesting. Somehow I don't think I knew that generators could
exist outside of generator functions (using yield)! I was wondering why
the second one above worked without brackets. :)
More information about the Python-list
mailing list