Skip to content

Instantly share code, notes, and snippets.

@daevaorn
Forked from kmerenkov/chunkify.py
Created July 8, 2010 16:01
Show Gist options
  • Save daevaorn/468216 to your computer and use it in GitHub Desktop.
Save daevaorn/468216 to your computer and use it in GitHub Desktop.
from itertools import izip
def chunkify(iterable, chunk_size):
r"""
>>> chunkify(range(1, 11), 2)
[(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
"""
_iterable = iter(iterable)
return izip(*[_iterable] * chunk_size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment