inverse of izip
Steven Bethard
steven.bethard at gmail.com
Thu Aug 19 02:07:50 EDT 2004
So I know that zip(*) is the inverse of zip(), e.g.:
>>> zip(*zip(range(10), range(10)))
[(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)]
What's the inverse of izip? Of course, I could use zip(*) or izip(*),
e.g.:
>>> zip(*itertools.izip(range(10), range(10)))
[(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)]
>>> x, y = itertools.izip(*itertools.izip(range(10), range(10)))
>>> x, y
((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
But then I get a pair of tuples, not a pair of iterators. Basically,
I want to convert an iterator of tuples into a tuple of iterators.
Steve
More information about the Python-list
mailing list