I think one of the easiest ways to understand what is happening in the code is to realize that reverse slicing changes the direction of the index of your list (visually, this is like changing the list) before slicing , but the indices of the elements in the list by themselves do not change.
Thus, when you have a list like this:
['jumbly', 'wumbly', 'number', 5] 0 1 2 3
making it a reverse read (adding -1
as the third indexer), you make it look like this (because now it is indexed from the last to the first, and not from the first to the last):
[5, 'number', 'wumbly', 'jumbly'] 3 2 1 0
and then when you cut the “start” into one ( :1
), you get everything from the “start” (now the “start” 3
) and stops when you view 1
:
[5, 'number', 'wumbly', 'jumbly'] 3 2 1 0
So you got your return:
[5, 'number']
The same principle applies when you drop a slice using [:2:-1]
:
[5, 'number', 'wumbly', 'jumbly'] 3 2 1 0
So you got your result:
[5]
Now, using this principle, you know what to add as a second indexer if you want to return what you want: zero! → [:0:-1]
:
[5, 'number', 'wumbly', 'jumbly'] 3 2 1 0
Then you will get the result you want:
[5, 'number', 'wumbly']