I need to take a list of any length and shift it by some integer value. In this particular application, the list can be considered "cyclic" such that a shift of 1 to the right would result in the last value ending up at the first value.
This is the best I've got to (much better than all of my variants containing for loops),and it seems to work, but I wonder if there is something faster, particularly as these lists get very long.
def shift(p, U):
U = -(U % len(p))
q = p[U:]+p[:U]
return q