PEP 289: Generator Expressions (please comment)
Bruno Desthuilliers
bdesth.nospam at removeme.free.fr
Fri Nov 7 07:22:50 EST 2003
Raymond Hettinger wrote:
>
> http://www.python.org/peps/pep-0289.html
>
> 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)
> min(d.temperature()*9/5 + 32 for d in days)
> Set(word.lower() for word in text.split() if len(word) < 5)
> dict( (k, somefunc(k)) for k in keylist )
> dotproduct = sum(x*y for x,y in itertools.izip(xvec, yvec))
> bestplayer, bestscore = max( (p.score, p.name) for p in players )
>
> Each of the above runs without creating a full list in memory,
> which saves allocation time, conserves resources, and exploits
> cache locality.
>
+3.1415926535897931 for me.
Bruno
More information about the Python-list
mailing list