Skip to content

Instantly share code, notes, and snippets.

@lucidfrontier45
Last active July 21, 2016 02:26
Show Gist options
  • Select an option

  • Save lucidfrontier45/18e54438eb36fe8d2501 to your computer and use it in GitHub Desktop.

Select an option

Save lucidfrontier45/18e54438eb36fe8d2501 to your computer and use it in GitHub Desktop.
batch iterator
from itertools import islice, chain
def batches(iterable, batchsize=10):
it = iter(iterable)
while True:
batch = islice(it, batchsize)
yield chain([next(batch)], batch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment