Skip to content

Instantly share code, notes, and snippets.

@byronyi
Forked from andrix/iunzip.py
Last active August 29, 2015 14:22
Show Gist options
  • Save byronyi/431f649e644b8671dc8b to your computer and use it in GitHub Desktop.
Save byronyi/431f649e644b8671dc8b to your computer and use it in GitHub Desktop.
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