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

Source Code

mylist = []
size = int(input('How many elements you want to enter? '))

print('Enter',str(size),'elements')

for i in range(size):
    data = input()
    mylist.append(data)
    
print('list before shifting', mylist)

temp = mylist[size-1]

for i in range(size-1,0,-1):
    mylist[i] = mylist[i-1]

mylist[0] = temp

print('list after shifting', mylist)

Output

How many elements you want to enter? 4
Enter 4 elements
sunday
monday
tuesday
wednesday
list before shifting ['sunday', 'monday', 'tuesday', 'wednesday']
list after shifting ['wednesday', 'sunday', 'monday', 'tuesday']