Backward list indices

Fredrik Lundh fredrik at pythonware.com
Fri Dec 20 03:22:01 EST 2002


Nicola Larosa wrote:

> Why is that so? It would seem natural that, if i is greater than or
> equal to j, the slice is populated with the items in backward order,
> be it myList[5:3] or myList[-3:-7] .

which items?

note that python 2.3 lets you specify the step size:

>>> myList = range(10)
>>> myList[3:5]
[3, 4]
>>> myList[3:5:1]
[3, 4]
>>> myList[5:3]
[]
>>> myList[5:3:-1]
[5, 4]
>>>

(principles 2, 12 and 13 from http://www.python.org/dev/culture.html
might apply here...)

</F>





More information about the Python-list mailing list