Last active
July 21, 2016 02:26
-
-
Save lucidfrontier45/18e54438eb36fe8d2501 to your computer and use it in GitHub Desktop.
batch iterator
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
| from itertools import islice, chain | |
| def batches(iterable, batchsize=10): | |
| it = iter(iterable) | |
| while True: | |
| batch = islice(it, batchsize) | |
| yield chain([next(batch)], batch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment