Re: Iterator for circulating a list

2007-11-13 Thread BJörn Lindqvist
On Nov 13, 2007 3:43 PM, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Tue, 2007-11-13 at 15:12 +0100, BJörn Lindqvist wrote: > > L = somelist > > > > idx = 0 > > while True: > > item = L[idx] > > # Do something with item > > idx = (idx + 1) % len(L) > For begin=0 and step=1, itertools.

Re: Iterator for circulating a list

2007-11-13 Thread Hrvoje Niksic
"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 > wh

Re: Iterator for circulating a list

2007-11-13 Thread Carsten Haese
On Tue, 2007-11-13 at 15:12 +0100, BJörn Lindqvist wrote: > 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 =

Iterator for circulating a list

2007-11-13 Thread BJörn Lindqvist
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) f