Rotating lists?

Raymond Hettinger vze4rx4y at verizon.net
Thu Sep 16 00:50:17 CEST 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