Skip to content

Instantly share code, notes, and snippets.

@aaronsaunders
Created October 19, 2012 18:43
Show Gist options
  • Save aaronsaunders/3919920 to your computer and use it in GitHub Desktop.
Save aaronsaunders/3919920 to your computer and use it in GitHub Desktop.
def grouperchunker(seq, size):
return (seq[pos:pos + size] for pos in xrange(0, len(seq), size))
for group in grouper(animals, 3):
print group
from itertools import
def grouper(n, iterable, fillvalue=None):
"Collect data into fixed-length chunks or blocks"
# grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx
args = [iter(iterable)] * n
return izip_longest(fillvalue=fillvalue, *args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment