I want to swap the consecutive elements of a list such that the first element will go to the last. eg [4, 7, 3, 4, 3]
should print as [7,3,4,3,4]
This is the code I've written but it doesn't work right. How can I modify it to get it working?
ls = [4, 7, 3, 4, 3]
i=0
b=1
while i+1<len(ls):
ls[i]=a
ls[i]=ls[i+1]
ls[i+1]=a
i+=1
print ls
I do not want to just switch the first element with the last one. I want to modify this code further to create a bubble sort algorithm, I am just confused at how to get done what I just explained.
Updated : Thanks for the answer that I should change "ls[i]=a" with "a=ls[i]", but can someone explain to me how this differs in logic?