Skip to content

Instantly share code, notes, and snippets.

@grenzi
Created November 15, 2021 22:06
Show Gist options
  • Save grenzi/1dacbf7fd60c423ce7542990f2e43e4f to your computer and use it in GitHub Desktop.
Save grenzi/1dacbf7fd60c423ce7542990f2e43e4f to your computer and use it in GitHub Desktop.
# just a simple way to process an iterable in chunks
def batch(iterable, n=1):
l = len(iterable)
for i in range(0, l, n):
yield iterable[i:min(i + n, l)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment