Alternative to standard C "for"

Alex Martelli aleaxit at yahoo.com
Sat Feb 5 14:14:55 EST 2005


Georg Brandl <g.brandl-2005-01 at gmx.net> wrote:

> Slight terminology glitch -- it does return an iterator, not a
> generator. Generators are functions that return iterators.

xrange returns an ITERABLE, not an ITERATOR.  Videat:

>>> a = xrange(23, 43)
>>> a.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'xrange' object has no attribute 'next'
>>> 

No next method -> not an iterator.  iter(xrange(...)) DOES return an
iterator, btw.


Alex



More information about the Python-list mailing list