Created
June 23, 2021 05:27
-
-
Save rmporsch/2efe69ddb38b6a6972a02c9aa57397f5 to your computer and use it in GitHub Desktop.
[Batching] #python
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
def batching(iterable: Sized, n: int = 1) -> Iterator: | |
""" | |
Batch a list or iterable | |
:param iterable: | |
:param n: items per batch | |
:return: iterator | |
""" | |
length = len(iterable) | |
for ndx in range(0, length, n): | |
yield iterable[ndx:min(ndx + n, length)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment