To avoid None
s, you can use snippets :
def chunks(seq, n): # /questions/1021/how-do-you-split-a-list-into-evenly-sized-chunks/15485#15485 (Ned Batchelder) """ Yield successive n-sized chunks from seq.""" for i in xrange(0, len(seq), n): yield seq[i:i + n] for i,group in enumerate(dynamic_grouper(iterable, chunk_sizes)): for item in chunks(group, 5): print "Group %i" % i print "Items %s" % list(item)
source share