xxxxxxxxxx
#Shifts all elements one to the right and moves end value to the start
li=li[-1:]+li[:-1]
xxxxxxxxxx
list = [0,1,2,3]
#shifted backwards (to left)
list.append(list.pop(0))
print(list)
list = [0,1,2,3]
#shifted forward (to right)
list.insert(0,list.pop())
print(list)
#Output:
[1,2,3,0]
[3,0,1,2]
xxxxxxxxxx
def shiftRight(lst) :
return lst[-1:] + lst[:-1]
def shiftLeft(lst) :
return lst[1:] + lst[:1]