negative stride list slices
Reid Nichol
rnichol_rrc at yahoo.com
Wed Sep 1 16:43:44 EDT 2004
Russell Blau wrote:
> "Reid Nichol" <rnichol_rrc at yahoo.com> wrote in message
> news:r7oZc.6653$MR2.32885 at news1.mts.net...
>
>>David Abrahams wrote:
>>
>>>Can anyone explain the logic behind the behavior of list slicing with
>>>negative strides? For example:
>>>
>>> >>> print range(10)[:-3:-1]
>>> [9,8]
>>>
>>>I found this result very surprising, and would just like to see the
>>>rules written down somewhere.
>>
> http://www.python.org/doc/current/tut/node5.html#SECTION005120000000000000000
>
> You probably meant to reference the next section (that bookmark relates to
> strings, the next one is lists), but in either case none of the examples in
> the tutorial has yet been updated to deal with slices that include a
> "stride" as a third parameter.
>
>
This was the part that I was refering to:
+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4 5
-5 -4 -3 -2 -1
Does it not all work the same in practice?
More information about the Python-list
mailing list