Skip to content

Instantly share code, notes, and snippets.

@andrix
Created July 4, 2011 13:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrix/1063340 to your computer and use it in GitHub Desktop.
Save andrix/1063340 to your computer and use it in GitHub Desktop.
python iterable unzip
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