Programming Examples

Python program to rotate list elements with next elements


Write a program 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 element at the last index moves to the first index.

Solution

lst=eval(input("Enter a list : "))
print("List before Rotation :",lst)
a=lst[0]
s=len(lst)
for i in range(1,s):
    lst[i-1]=lst[i]
lst[s-1]=a
print("List after Rotate :",lst)
Output

Enter a list : [3,4,5,6]

List before Rotation : [3, 4, 5, 6]

List after Rotate : [4, 5, 6, 3]

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad