I want to rotate elements in a list, e.g. - shift the list elements to the right so [\'a\',\'b\',\'c\',\'d\'] would become [\'d\',\'a\',\'b\',\'c\'], o
[\'a\',\'b\',\'c\',\'d\']
[\'d\',\'a\',\'b\',\'c\']
You can just slice the last element off the list, then add it to the beginning of a new list:
aList = [aList[-1]] + aList[:-1]
Here is the result:
>>> aList = [1,2,3] >>> aList = [aList[-1]] + aList[:-1] >>> aList [3, 1, 2]