Suppose I have a list:
>>> numbers = list(range(1, 15))
>>> numbers
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
I need reverse last 10 element only using slice notation
At first, I try just slice w/o reverse
>>> numbers[-10:]
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
Then:
>>> numbers[-10::-1]
I expected [14, 13, 12, 11, 10, 9, 8, 7, 6, 5]
but got [5, 4, 3, 2, 1]
.
I can solve the problem like this:
numbers[-10:][::-1]
and everything OK
[14, 13, 12, 11, 10, 9, 8, 7, 6, 5]
But I wondering why numbers[-10::-1]
doesn't work as expected in my case and if there a way to get the right result by one slice?