circular iteration
Duncan Booth
duncan.booth at invalid.invalid
Fri Jan 21 11:40:35 EST 2005
Flavio codeco coelho wrote:
> hi,
>
> is there a faster way to build a circular iterator in python that by
> doing this:
>
> c=['r','g','b','c','m','y','k']
>
> for i in range(30):
> print c[i%len(c)]
>
> thanks,
>
> Flávio
>
>>> import itertools
>>> c=['r','g','b','c','m','y','k']
>>> circ = itertools.cycle(c)
>>> for i in range(30):
print circ.next(),
r g b c m y k r g b c m y k r g b c m y k r g b c m y k r g
>>>
More information about the Python-list
mailing list