Skip to content

Instantly share code, notes, and snippets.

@hdemers
Created April 8, 2013 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdemers/5339577 to your computer and use it in GitHub Desktop.
Save hdemers/5339577 to your computer and use it in GitHub Desktop.
A Python generator yielding a list in chunks. Cf. http://stackoverflow.com/a/312464
def chunks(l, n):
""" Yield successive n-sized chunks from l.
Cf. http://stackoverflow.com/a/312464
"""
for i in xrange(0, len(l), n):
yield l[i:i+n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment