Can i reverse a List within a particular Range in python?

i mean Suppose I have a List [1,2,3,4,5,6,7,8,9] i want to reverse its number in a particular range like from 2 to 5 so the expected output is [1,2,6,5,4,3,7,8,9]

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

Answer

You can do it by just considering the slice of the list and reversing it.

example:

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]