Reverse a part (slice) of a list
You have a list and you want to reverse a part (slice) of it.
Let our list be
[1,2,9,6,5] and say we want to reverse its end from element 9, i.e. we want to get
a = [1,2,9,6,5] i = 2 # reverse from this index position j = 4 # reverse until this index position (included) a[i:j+1] = reversed(a[i:j+1]) print a # [1, 2, 5, 6, 9]