This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients Akshay Deogaonkar, steven.daprano
Date 2017-04-22.18:16:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1492885003.06.0.227604956807.issue30137@psf.upfronthosting.co.za>
In-reply-to
Content
The behaviour is as documented and is not a bug. When you have a three-argument extended slice, the starting and stopping values depend on whether the stride (step) is positive or negative. Although that's buried in a footnote to the table.

https://docs.python.org/3/library/stdtypes.html#common-sequence-operations

The current behaviour is necessary so that the common case of both start and stop being blank is supported correctly for negative stride:

py> "abcde"[::-1]
'edcba'


So with a positive stride, your first example lst[0:3:-1] starts at index 0, ends at index 3, with step -1. That is an empty slice.

But your second example lst[:3:-1] starts at the end of the list, index len(lst), ends at 3, with step -1. That is equivalent to lst[5:3:-1] which is not the same as your first example.
History
Date User Action Args
2017-04-22 18:16:43steven.dapranosetrecipients: + steven.daprano, Akshay Deogaonkar
2017-04-22 18:16:43steven.dapranosetmessageid: <1492885003.06.0.227604956807.issue30137@psf.upfronthosting.co.za>
2017-04-22 18:16:43steven.dapranolinkissue30137 messages
2017-04-22 18:16:42steven.dapranocreate