1 2 3 4 5 6 7 8 9 10 11 12 13 14
# chop.py # see also http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279 import itertools def chop(iterable, batchsize): it = iter(iterable) while True: batch = list(itertools.islice(it, batchsize)) if batch: yield batch else: break