Created
October 15, 2014 12:51
-
-
Save bcho/738e84524d1d9ba4b625 to your computer and use it in GitHub Desktop.
trick
This file contains hidden or 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
| # coding: utf-8 | |
| def chunks(seq, chunk_size): | |
| '''Split a sequence into chunks. | |
| Source: http://stackoverflow.com/a/312464/1158494 | |
| :param seq: sequence to be split. | |
| :param chunk_size: chunk size. | |
| ''' | |
| assert(chunk_size > 0), 'Chunk size must be postive.' | |
| for i in range(0, len(seq), chunk_size): | |
| yield seq[i:i+chunk_size] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment