In article <5.2.1.1.0.20040430142620.030304e8@pop.bluewin.ch>,
Samuele Pedroni
... this assumes that people will choose either generator expressions or list comprehesions on a case-by-case basis. I'm not sure it's a reasonable assumption for the whole range of users - starting with newbies. Probably documentation and what is predicated on c.l.p will influence this.
I completely agree. Generator expressions and list comprehensions are similar enough that it seems a wart to have to carefully differentiate between two in normal use. Personally, I'd only like to see generator expressions added to Python if they can allow list comprehensions to be deprecated -- to avoid language clutter. One question, though: is "if" part of generator expressions or not? I read the current version of the PEP and I'm confused. It offers the example: max(len(line) for line in file if line.strip()) But that is the only instance in the PEP that I noticed. The section "The Details" says almost nothing about "if". The only thing I found that might be relevant appeared at the end of: "2. The syntax requires...": "...where listmaker1 is almost the same as listmaker, but only allows a single test after 'for' ... 'in'." I suppose that might be saying that a single "if" condition is allowed. If so, great! -- Russell