PEP 289: Generator Expressions (please comment)

kirby urner urnerk at qwest.net
Tue Nov 4 15:12:38 EST 2003


Alex Martelli <aleax at aleax.it> wrote in message news:

> d = (f(p) for p in X if g(p))
> 
> will have the same semantics as:
> 
> def _aux():
>     for p in X:
>         if g(p):
>             yield f(p)
> d = _aux()
> del _aux
> 
> no more, no less.
> 
> 
> Alex

OK, thanks for the clarification.  Not creating an indexable, just an
iterable, got it.  Some analogy with list comprehensions was throwing
me off.

So X in the above could be a a generator-based iterable too.  This'd
be one way to feed generators from other generators.

Kirby




More information about the Python-list mailing list