def takeby(i, n): it = iter(i) while True: yield [it.next() for x in range(n)] for a, b, c in takeby(range(20), 3): print a, b, c