Wrapping around a list as a slice operation

Rotate left n elements (or right for negative n):

L = L[n:] + L[:n]

Note that collections.deque has support for rotations. It might be better to use that instead of lists.

Leave a Comment