What's do list comprehensions do that generator expressions don't?

Jeremy Bowers jerf at jerf.org
Tue Apr 26 15:00:09 EDT 2005


On Tue, 26 Apr 2005 02:12:07 -0500, Mike Meyer wrote:
> Right. But that shouldn't be hard to do. Let genexp stand for a a
> generator expression/list comprehension without any brackets on it at all.
> Then [genexp] is the syntax to expand the list. [(genexp)] is the syntax
> to create a list of one element - a generator object. foo(genexp) will do
> the right thing.

In other words, everything as it is today, only with different
implementations under the hood. :-)

Rolling back around to the original point, I don't see any reason to ban
[x for x in thing], changing current practice, when it is so easy to keep
it. [(x for x in thing)] is also current practice (perhaps "bad style" in
some sense, but definately possible in 2.4), and I don't think there is a
good reason to change that, either.



More information about the Python-list mailing list