Rotating lists?

Ivan Voras ivoras at __-geri.cc.fer.hr
Thu Sep 16 11:13:25 EDT 2004


Irmen de Jong wrote:
> This smells like a use-case for itertools.cycle:
> 
>  >>> import itertools
>  >>> c=itertools.cycle( [1,2,3] )
>  >>> c.next()
> 1
>  >>> c.next()
> 2
>  >>> c.next()
> 3
>  >>> c.next()
> 1
>  >>> c.next()
> 2
> 
> ... or is this not what you need to rotate your lists for?

No, I don't need an (infinite) cycle, just the rotated list. But thanks, 
I didn't notice itertools before :)



More information about the Python-list mailing list