"BJörn Lindqvist" <[EMAIL PROTECTED]> writes:

> L = somelist
>
> idx = 0
> while True:
>     item = L[idx]
>     # Do something with item
>     idx = (idx + 1) % len(L)
>
> wouldn't it be cool if there was an itertool like this:
>
> def circulate(L, begin = 0, step = 1):
>     idx = begin
>     while True:
>         yield L[idx]
>         idx = (idx  + step) % len(L)
>
> for x in circulate(range(10)):
>     print 'at', x,'!'

How about itertools.cycle?
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to