PEP 289: Generator Expressions (please comment)

Paul Rubin http
Thu Oct 23 21:09:29 EDT 2003


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)

Note there's no builtin function "sum".  It's always annoyed me that
operator.add always takes exactly two arguments, so you have to use
reduce.  I'd like to be able to say operator.add(2,3,4), or in the
generator expression case, operator.add(yield x*x for x in roots).




More information about the Python-list mailing list