summaryrefslogtreecommitdiff
path: root/pypers/oxford/chop.py
diff options
context:
space:
mode:
Diffstat (limited to 'pypers/oxford/chop.py')
-rwxr-xr-xpypers/oxford/chop.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/pypers/oxford/chop.py b/pypers/oxford/chop.py
new file mode 100755
index 0000000..3325d52
--- /dev/null
+++ b/pypers/oxford/chop.py
@@ -0,0 +1,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
+
+