Programming Examples

Python program to rotates the elements of list so that fist elements move to second and second to the third


python program to rotates the elements of list so that fist elements move to second and second to the third

Write a python program to rotates the elements of a list so that the elements at the first index moves to the second index, the element in the second index moves to the third index, etc. and the elements in the last index moves to the first index.

mylist=eval(input("Enter any List of Integer : "))
temp=mylist[len(mylist)-1]
for a in range(len(mylist)-1,0,-1):
    mylist[a]=mylist[a-1]
mylist[0]=temp
print("After Shift List is : ",mylist)
Output

Enter any List of Integer : [3,5,8,9,6]

After Shift List is :  [6, 3, 5, 8, 9]

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad