need help on generator...

Francis Girard francis.girard at free.fr
Fri Jan 21 11:54:47 EST 2005


Thank you,

I immediately download version 2.4, switching from version 2.3.

Francis Girard
FRANCE

Le vendredi 21 Janvier 2005 17:34, Craig Ringer a écrit :
> On Fri, 2005-01-21 at 16:54 +0100, Francis Girard wrote:
> > First, I think that you mean :
> >
> > consecutive_sets = [ x[offset:offset+subset_size]
> >                       for subset_size in xrange(2, len(x))
> >                       for offset in xrange(0, len(x) + 1 - subset_size)]
> >
> > (with square brackets).
> >
> > I'm just trying to understand and obviously I'm missing the point.
>
> Yep. This:
>
> ( x for x in xrange(10) )
>
> will return a generator that calculates things as it goes, while this:
>
> [ x for x in xrange(10) ]
>
> will return a list.
>
> Check out:
> 	http://www.python.org/peps/pep-0289.html
> 	http://docs.python.org/whatsnew/node4.html
> 	http://www.python.org/dev/doc/newstyle/ref/genexpr.html
> for details.
>
> --
> Craig Ringer




More information about the Python-list mailing list