PEP 260: simplify xrange()

Guido van Rossum guido at python.org
Tue Jun 26 16:51:00 EDT 2001


Roman Suzi <rnd at onego.ru> writes:

> But after PEP 260 xrange is sequence no more.

Since there's no formal definition of a sequence, there's little basis
on which to agree, but to me, as long as it supports len(x) and x[i],
it's a sequence alright.

> And also I think  "x in xrange(...)" and
> "x not in xrange(...)" should not be dropped,
> because it is very near to
> 
> for x in xrange(...)

But unlike that one it has very few practical uses.

> and has interesting use as in:
> 
> if n in xrange(1, 101, 2): # odd number from [1, 100]
>   ...

This is exactly the kind of odd usage that gave xrange() a bad name,
and contained an off-by-one bug for a while.  It also used to be real
slow until we had __contains__ (because it would iterate over the
items comnparing n to each one), and nobody missed it.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list