Last active
April 26, 2018 08:18
-
-
Save arc279/ac9783043c1921580f34facd3f2d9599 to your computer and use it in GitHub Desktop.
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 each_slice(iterable, n): | |
| for i, item in itertools.groupby(enumerate(iterable), lambda x: x[0] // n): | |
| yield (x[1] for x in item) | |
| for x in each_slice(range(10), 3): | |
| print(tuple(x)) | |
| """output | |
| (0, 1, 2) | |
| (3, 4, 5) | |
| (6, 7, 8) | |
| (9,) | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment