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]

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