All pastes #839630 Raw Edit

Miscellany

public python v1 · immutable
#839630 ·published 2007-12-31 03:24 UTC
rendered paste body
def 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()