PEP 289: Generator Expressions (please comment)

Donald 'Paddy' McCarthy paddy3118 at netscape.netNOTthisBIT
Thu Oct 23 23:40:45 EDT 2003



Paul Rubin wrote:
> python at rcn.com (Raymond Hettinger) writes:
> 
>>In brief, the PEP proposes a list comprehension style syntax for
>>creating fast, memory efficient generator expressions on the fly:
>>
>>    sum(x*x for x in roots)
> 
> 
> This is a little confusing.  Consider:
> 
> 1)     [x*x for x in roots]
> 2)     (x*x for x in roots)
> 
> #2 looks like it should be a "sequence comprehension" and not a
> generator expression.  I'd go back to your earlier proposal of
> using a yield keyword if you want a generator expression:
> 
>     sum(yield x for x in roots)
> 
I too prefer the above use of yield because then you can always 
associate generators with the yield keyword.

Pad.





More information about the Python-list mailing list