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 use negative indices together with list concatenation:
def shift(seq, n=0): a = n % len(seq) return seq[-a:] + seq[:-a]