Last active
August 9, 2022 19:18
-
-
Save rafaelhenrique/d984f44a9ced20b76350b35048abd826 to your computer and use it in GitHub Desktop.
Generate chunks
This file contains hidden or 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
import itertools | |
def generate_chunks(data, chunk_size: int): | |
iterable = iter(data) | |
while chunk := tuple(itertools.islice(iterable, chunk_size)): | |
yield chunk | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A cool use of this...