Created
December 17, 2013 17:12
-
-
Save gonz/8008641 to your computer and use it in GitHub Desktop.
iterator split_every
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 split_every(n, iterable): | |
i = iter(iterable) | |
piece = list(islice(i, n)) | |
while piece: | |
yield piece | |
piece = list(islice(i, n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment