Range Operation pre-PEP

Roman Suzi rnd at onego.ru
Wed May 9 04:25:38 EDT 2001


On Wed, 9 May 2001, Thomas Wouters wrote:

>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.

I think, ".." will be just another way to write xrange.
If it ever will be an iterator - so will be "..".

Or it could be some yet-to-implement irange, which
can be read as "inclusive range" or "iterator-creating range"
-- this must not stop from proposing ".." notation now.

This small feature will make Python's for loops much
friendlier to beginners.

I do not fear

for i in 0..len(mylist)-1

because this is _explicit_ writing of the fact mylist
is indexed from 0. If there will be errors, they will
cause IndexErrors and not some subtle logical errors.

Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Wednesday, May 09, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Always remember no matter where you go, there you are." _/





More information about the Python-list mailing list