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\']
If you are trying to shift the elements, use collections.deque rotate method:
#! /usr/bin/python3 from collections import deque a = deque([1, 2, 3, 4]) a.rotate() print(a)
Result:
[2, 3, 4, 1]