PEP 289: Generator Expressions (please comment)

Peter Hansen peter at engcorp.com
Thu Oct 23 16:58:18 EDT 2003


Daniel Dittmar wrote:
> 
> Raymond Hettinger wrote:
> >     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.
> 
> Why should generator comprehension be useful only for arguments?
> 
> counter proposal:
> g[(p.score, p.name) for p in players ]
> 
> This works similar to r'\' for raw strings and u'x' for unicode strings.

Except that r'' can mean nothing else, syntactically, while g[something]
could be a dictionary lookup using <something> as the key.




More information about the Python-list mailing list