How do I use the slice syntax of python to get a list from 0
to i
in reversed order?
For example, if the list is [1, 2, 3, 4]
and i == 2
, the result should be [3 ,2 ,1]
.
How do I use the slice syntax of python to get a list from 0
to i
in reversed order?
For example, if the list is [1, 2, 3, 4]
and i == 2
, the result should be [3 ,2 ,1]
.
The 2 is the first character instead of the second because it takes effect after the reversal (you take steps backwards)
>>> [1,2,3,4][2::-1]
[3, 2, 1]