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

T

Terry Reedy

Mike Meyer said:
The question under these circumstances is then: do you want bare
genexp to mean something? Right now, it's a syntax error. But there's
no reason you couldn't have:

y = x for x in stuff

assign a generator object to y.

Since this was considered, there is a reason why we don't have this. As I
remenber, but vaguely, Guido's reasoning was both stylistic and technical,
but you'd have to check the archives for more.

Terry J. Reedy
 
R

Reinhold Birkenfeld

Mike said:
The question under these circumstances is then: do you want bare
genexp to mean something? Right now, it's a syntax error. But there's
no reason you couldn't have:

y = x for x in stuff

I like

y = (x for x in stuff)

as it is, it's way more readable.

Reinhold
 
J

Jeremy Bowers

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.
 
B

Bengt Richter

Since this was considered, there is a reason why we don't have this. As I
remenber, but vaguely, Guido's reasoning was both stylistic and technical,
but you'd have to check the archives for more.
Because it is too reminiscent of a lambda expression assignment? ;-)

Regards,
Bengt Richter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top