Skip to content

Instantly share code, notes, and snippets.

@raphaelfruneaux
Last active January 5, 2022 21:26
Show Gist options
  • Save raphaelfruneaux/b6a53eae7b6d2d1af0e9efa928109267 to your computer and use it in GitHub Desktop.
Save raphaelfruneaux/b6a53eae7b6d2d1af0e9efa928109267 to your computer and use it in GitHub Desktop.
This function split an iterable into a new iterable with pieces of a certain size
from itertools import islice
def split_in_chunks(iterable, size=10):
iterable = iter(iterable)
while chunk := tuple(islice(iterable, size)):
yield chunk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment