i mean Suppose I have a List
i want to reverse its number in a particular range like from 2 to 5 so the expected output is
NB: I don’t want to use a Loop and by swapping each values, don’t want to use extra space. is it possible? like the reverse() function
You can do it by just considering the slice of the list and reversing it.
a[2:6] = a[2:6][::-1]
This also can be achieved much faster, considering the answer from @Tom Karzes.
a[2:6] = a[5:1:-1]