def cycle(lnums): c = 0 while True: yield lnums[c % len(lnums)] c += 1