StopIteration in the if clause of a generator expression
Simon Brunning
simon.brunning at gmail.com
Tue Apr 5 04:51:55 EDT 2005
On Apr 5, 2005 2:04 AM, Raymond Hettinger <vze4rx4y at verizon.net> wrote:
> [Steven Bethard]
> > So do I read this right in preferring
> > [<x> for <y> in <z>]
> > over
> > list(<x> for <y> in <z>)
>
> Yes!
Why? (Serious question. I'm sure that you have a good reason - I just
can't figure out what it is.)
The generator expression has the advantage of not leaking references
into the enclosing namespace. What's advantage of the list comp?
--
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/
More information about the Python-list
mailing list