Q. Write a Program to shift elements of a list so that the first element moves to the second index and second index moves to the third index, and so on, and the last element shifts to the first position.

 

Suppose the list is [10, 20, 30, 40]

After shifting, it should look like: [40, 10, 20, 30]

 

Answer = 

 



lst = eval(input("enter the list = "))
print ("New list =", [lst[ -1] ] + lst[0 : -1] )

 

8 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post