List rotation
Steven Bethard
steven.bethard at gmail.com
Wed Sep 29 23:43:17 EDT 2004
M. Clift <noone <at> here.com> writes:
>
> Could someone help me out with this?
>
> items = ('a', 'b', 'c', 'd')
> items + 1 = ( 'b', 'c', 'd', 'a')
Is it necessary to (ab)use the + syntax? If not, will this suffice:
>>> def rotate(seq, n):
... return seq[n:] + seq[:n]
...
>>> rotate(range(10), 1)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
>>> rotate(range(10), 2)
[2, 3, 4, 5, 6, 7, 8, 9, 0, 1]
You also might want to search google groups for more information. If I
understand your question right, this has been asked a number of times, for
example:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-
8&safe=off&selm=3c4e7b1a.1031701568%40news.mch.sni.de
More information about the Python-list
mailing list