summaryrefslogtreecommitdiff
path: root/pypers/oxford/chop.py
blob: 3325d5294bbabd878270ce2e3d0e8379b69d508c (plain)
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