Skip to content

Instantly share code, notes, and snippets.

@nicholsn
Created October 22, 2015 01:30
Show Gist options
  • Select an option

  • Save nicholsn/108a7fb64e0e7567d2f0 to your computer and use it in GitHub Desktop.

Select an option

Save nicholsn/108a7fb64e0e7567d2f0 to your computer and use it in GitHub Desktop.
processing records in batches
def batch(iterable, n=1):
"""
For batch processing of records
:param iterable:
:param n: batch size
:return: generator
"""
l = len(iterable)
for ndx in range(0, l, n):
yield iterable[ndx:min(ndx + n, l)]
# Example:
# for record in batch(range(1, 100), n=10)
# print record
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment