PEP 289: Generator Expressions (please comment)

Ian McMeans imcmeans at telus.net
Sat Oct 25 14:40:25 EDT 2003


I really like this. Not only is it less of a special case (than using
[]), but it makes it easy to use comprehensions for other data types.
I think that using the yield keyword makes it more obviously a
generator.

sum(x for x in lst) makes it clear what it will compute, but not that
it will be computed using a generator. sum(yield x for x in lst) makes
it more apparent that you're creating a generator and passing it to
sum.

chrisperkins37 at hotmail.com (Chris Perkins) wrote in message news:<45228044.0310240442.4903f866 at posting.google.com>...
> Raymond Hettinger:
> >
> >     http://www.python.org/peps/pep-0289.html
> > 
> 
> I like it. This made me realize that list comprehension sytax is a
> special case that never really needed to be special-cased.
> 
> In fact, list comprehensions themselves become redundant syntactic
> sugar under the new proposal:
> 
> [foo(x) for x in bar] ==> list(foo(x) for x in bar)
> 
> Chris Perkins




More information about the Python-list mailing list