Last active
August 29, 2015 14:06
-
-
Save nicolamontecchio/d273802d6264fa33a715 to your computer and use it in GitHub Desktop.
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
# groups of `size` from an iterable `seq` | |
def group(seq, size): | |
it = iter(seq) | |
while True: | |
values = [] | |
try: | |
for n in xrange(size): | |
values.append(it.next()) | |
yield values | |
except: | |
break | |
if len(values) > 0: | |
yield values |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment