Created
July 4, 2011 13:33
-
-
Save andrix/1063340 to your computer and use it in GitHub Desktop.
python iterable unzip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
from operator import itemgetter | |
def iunzip(iterable): | |
"""Iunzip is the same as zip(*iter) but returns iterators, instead of | |
expand the iterator. Mostly used for large sequence""" | |
_tmp, iterable = itertools.tee(iterable, 2) | |
iters = itertools.tee(iterable, len(_tmp.next())) | |
return (itertools.imap(itemgetter(i), it) for i, it in enumerate(iters)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment