Skip to content

Instantly share code, notes, and snippets.

@Flushot
Created June 14, 2013 22:46
Show Gist options
  • Select an option

  • Save Flushot/5785885 to your computer and use it in GitHub Desktop.

Select an option

Save Flushot/5785885 to your computer and use it in GitHub Desktop.
Yields n-sized chunks from a list l
def chunks(l, n):
"""Yields successive :n:-sized chunks from list :l:"""
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