Skip to content

Instantly share code, notes, and snippets.

@bcho
Created October 15, 2014 12:51
Show Gist options
  • Select an option

  • Save bcho/738e84524d1d9ba4b625 to your computer and use it in GitHub Desktop.

Select an option

Save bcho/738e84524d1d9ba4b625 to your computer and use it in GitHub Desktop.
trick
# 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