# coding: utf-8 def group(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]