need help on generator...
Craig Ringer
craig at postnewspapers.com.au
Fri Jan 21 11:34:47 EST 2005
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