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,'!' Or maybe someone knows an even better way of expressing the above code? -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list