PEP 276 Simple Iterator for ints

James_Althoff at James_Althoff at
Thu Nov 15 00:46:04 CET 2001

David Eppstein wrote:
>> [Tim Hochberg]
>> >So you can use it in your own class if you want. In particular, one
>> >make
>> >
>> >int[1,3,...,53] act like range(1,53,2) if one wanted.
>I missed this the first time it came around, but here is another argument
>why the current range syntax is not good: it confused Tim.
>What you want is for int[1,3,...,53] to act like range(1,54,2) or
>range(1,55,2) -- the final element of the range should be 53 not 51.

I believe this brings up a key point, namely, any proposal for a new
(Haskell-esque) syntax for specifying a sequence of integers is going to
face the problem of open versus closed intervals.  The difficulty is that a
syntax that calls for both ends to be specified (as most such proposals
do), as in for example "0 .. 5", will probably *look* like a closed
interval.  Unfortunately, the "most common case" of sequence indexing wants
a half-open interval -- closed on the left and open on the right -- *not* a
closed interval.  In current Python, range and xrange yield the half-open
interval that is ideal for sequence indexing.  The "half-openness" is
something that "just has to be learned". (But it is very convenient in the


More information about the Python-list mailing list