+ 1

Information practice class 11

Write a program in python to shift elements of a list so that first element moves to the second index and second index moves to the third index,etc,and last element shifts to the first position Suppose list is [10,20,30,40] After shifting it should look like : [ 20,30,40,10] if anyone can solve this please help. Don't spam

11th Nov 2020, 9:13 AM
Sam
Sam - avatar
3 Antworten
+ 1
Thanks for the answer. That's what I have wondering too. In my text the question was given like this. So I don't really know whether it's right or not
11th Nov 2020, 2:33 PM
Sam
Sam - avatar
0
list = [10,20,30,40] list = [list[-1]] + list[:-1]
11th Nov 2020, 9:34 AM
Mensch
Mensch - avatar
0
U said last element shifts to 1st position, itll be [40,10,20,30] not [20,30,40,10](1st to last)
11th Nov 2020, 9:36 AM
Mensch
Mensch - avatar