Skip to content

Instantly share code, notes, and snippets.

@ericmoritz
Created September 28, 2011 17:15
Show Gist options
  • Select an option

  • Save ericmoritz/1248533 to your computer and use it in GitHub Desktop.

Select an option

Save ericmoritz/1248533 to your computer and use it in GitHub Desktop.
List chunker
def chunk(l, size):
chunk_l = []
for x in l:
if len(chunk_l) == size:
yield chunk_l
chunk_l = [x]
else:
chunk_l.append(x)
for x in chunk(range(10), 2):
print x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment