Created
April 8, 2013 19:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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