Last active
January 5, 2022 21:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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