Range Operation pre-PEP

Thomas Wouters thomas at xs4all.net
Wed May 9 03:22:48 EDT 2001


On Tue, May 08, 2001 at 07:49:17PM -0300, Carlos Ribeiro wrote:

> Agreed. In fact, xrange could be internally substituted by iterators.

No, it could not. xrange(1,10)[3] works, iter(range(1,10))[3] does not:

>>> xrange(1,10)[3]
4
>>> iter(range(1,10))[3]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsubscriptable object
>>> 

xrange isn't an iterator, it's a 'generator' (or a 'lazy list'). I agree
that xrange should adhere to the iteration protocol, but making it *just* an
iterator isn't enough.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list