Rotating lists?

Raymond Hettinger vze4rx4y at verizon.net
Wed Sep 15 18:50:17 EDT 2004


[Ivan Voras]
> I need to transform this:
>
> [1,2,3]
>
> into this:
>
> [2,3,1]
>
> (a left-rotation. Actually, any rotation will do).

For Py2.4, use collections.deque.rotate().

For earlier Pythons, concatenate list slices:  a[1:] + a[:1]



Raymond Hettinger





More information about the Python-list mailing list