Steven D'Aprano added the comment:

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.

----------
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30137>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to