Question: What is the most efficient way to rotate a list in python? 
Right now I have something like this:

```
>>> def rotate(l, n):
...     return l[n:] + l[:n]
... 
>>> l = [1,2,3,4]
>>> rotate(l,1)
[2, 3, 4, 1]
>>> rotate(l,2)
[3, 4, 1, 2]
>>> rotate(l,0)
[1, 2, 3, 4]
>>> rotate(l,-1)
[4, 1, 2, 3]

```

Is there a better way?

Answer: 
I take this cost model as a reference:

<http://scripts.mit.edu/~6.006/fall07/wiki/index.php?title=Python_Cost_Model>

Your method of slicing the list and concatenating two sub-lists are linear-time operations. I would suggest using pop, which is a constant-time operation, e.g.:

```
def shift(list, n):
    for i in range(n)
        temp = list.pop()
        list.insert(0, temp)

```
For a list `X = ['a', 'b', 'c', 'd', 'e', 'f']` and a desired shift value of `shift` **less than list length**, we can define the function `list_shift()` as below

```
def list_shift(my_list, shift):
    assert shift < len(my_list)
    return my_list[shift:] + my_list[:shift]

```

Examples, 

`list_shift(X,1)` returns `['b', 'c', 'd', 'e', 'f', 'a']`
`list_shift(X,3)` returns `['d', 'e', 'f', 'a', 'b', 'c']`