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/ Explanation:

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

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

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad