Reorder an array in python
Question: I want to sort an array, so it starts off at

    
    
    order = [0,1,2,3,4,5]  #loop around trying all columns`
    

and then will go through, trying all combinations of this so 1,2,3,4,5,0 etc,
and stop once it has tried all of them.

Is there anyway to do this in python?


Answer: If you just want to "rotate" a list, have a look at the
[`deque`](http://docs.python.org/2/library/collections.html#deque-objects)
class:

    
    
    >>> from collections import deque
    >>> order = [0,1,2,3,4,5]
    >>> order.sort() # ensure order is sorted
    >>> q = deque(order)
    >>> for _ in xrange(len(q)):
    ...   q.rotate(-1)
    ...   print q
    ...
    deque([1, 2, 3, 4, 5, 0])
    deque([2, 3, 4, 5, 0, 1])
    deque([3, 4, 5, 0, 1, 2])
    deque([4, 5, 0, 1, 2, 3])
    deque([5, 0, 1, 2, 3, 4])
    deque([0, 1, 2, 3, 4, 5])
    >>>
    

