Reversing a list slice in python

The syntax is always [start:end:step] so if you go backwards your start needs to be greater than the end. Also remember that it includes start and excludes end, so you need to subtract 1 after you swap start and end.

l[5:2:-1]= [6, 5, 4]
l[4:1:-1]= [5, 4, 3]

Leave a Comment