[Python-ideas] [Python-Dev] Inclusive Range

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Oct 9 03:44:43 CEST 2010


On Fri, 08 Oct 2010 22:10:35 +0200, Hallvard B Furuseth wrote:

> Jed Smith <jed at jedsmith.org> writes:
>>>>> a = [1, 2, 3, 4, 5, 6]
>>>>> a[::-1]
>> [6, 5, 4, 3, 2, 1]
> 
> Nice.  Is there a trick to get a "-0" index too? Other than doing 'i or
> len(L)' instead of 'i', that is.

What exactly are you expecting? I don't understand why you think that 
L[-0] and L[0] would be different, when -0 == 0. I'm also unsure why you 
think that there's anything more ("too") to get -- the example shown 
reverses the entire list.

Perhaps if you show what result you are expecting, we can show what slice 
to give to get it.


>>>> L = [1,2,3,4,5]
>>>> L[2:-2], L[2:-1], L[2:-0]  # not quite right:-)
> ([3], [3, 4], [])


-- 
Steven



More information about the Python-list mailing list