rendered paste bodydef combine(*iterables): iterators = map(iter, iterables) primary, backups = iterators[0], iterators[1:] while True: try: yield primary.next() except StopIteration: try: primary = backups.pop(0) except IndexError: return else: for backup in backups: backup.next()import unittestclass TestCombine(unittest.TestCase): def test_simple(self): expected = [1] actual = list(combine([1])) assert expected == actual, actual def test_two_same_length(self): expected = [1,2] actual = list(combine([1,2], [3,4])) assert expected == actual, actual def test_two_different_lengths(self): expected = [1,2,5] actual = list(combine([1,2], [3,4,5])) assert expected == actual, actual def test_three(self): expected = [3,6,9] actual = list(combine([3], [5,6], [7,8,9])) assert expected == actual, actualif __name__ == "__main__": unittest.main()