[Python-Dev] PEP 289 - Generator Expressions - Let's Move Forward

Samuele Pedroni pedronis at bluewin.ch
Mon May 3 09:47:08 EDT 2004


At 21:08 02.05.2004 -0700, Guido van Rossum wrote:
> > Armin Rigo <arigo at tunes.org>:
> >
> > > Early binding is closer to the idea that turning a listcomp into a
> > > genexprs should just work if you only iterate once on the result.
>
>Greg Ewing:
> > I'm not sure that's an idea we should be promulgating in the first
> > place. The original motivation for generator expressions was things
> > like
> >
> >   total = sum(x**2 for x in stuff)
> >
> > where not only will the sequence be used just once, but it will be
> > used *immediately* before doing anything else.
> >

yes, but the question is how much easy is to grasp what "used 
*immediately*" means for a genexp, or IOW how much education is needed.

this looks innocent enough:

l = list_of_my_strings()
for pfx in discard_prefixes:
   l = ( x for x in l if not x.startswith(pfx) ) # this is not using l 
*immediately*
use_strings(l)


> > Those are the use cases we need to advertise this as targeting, I
> > think, not "any listcomp that's only used once".
>
>Right -- thanks for saying it so clearly!  Early binding seems to be
>trying to solve a problem with a use for genexprs that's questionable
>at best.




More information about the Python-Dev mailing list