# Re: range()

Guido van Rossum (Guido.van.Rossum@cwi.nl)
Mon, 29 Jun 1992 15:55:41 +0200

>In Python, you currently have to say:
>
> for i in range(len(a)-1,-1,-1):
>
>to iterate backwards over the indices of a list. Range should be
>defined so that you can simply say:
>
> for i in range(len(a),0,-1):
>
>If k>0, this could be done by defining
>
> range(m,n,-k)
>
>to be equivalent to
>
> range(n,m,k).reverse()
>
>That is to say, if the third argument is negative then the range
>that is produced includes the second argument but not the first.
>If the third argument is positive the range includes the first
>argument but not the second as is currently the case.

Interesting suggestion; at first I thought I'd agree with you
completely (barring backward compatibility, which I don't think will
be a big problem); but what about things like range(0, -5, -1)?
Currently this returns [0, -1, -2, -3, -4]; under Lou's proposed
definition it would change to [-1, -2, -3, -4, -5]. Intimate lovers
of two's complement arithmetic might expect that, but to me it feels
slightly uneasy.

Any other opinions?

--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"This is an ex-parrot"