Skip to content

Instantly share code, notes, and snippets.

@nicolamontecchio
Last active August 29, 2015 14:06
Show Gist options
  • Save nicolamontecchio/d273802d6264fa33a715 to your computer and use it in GitHub Desktop.
Save nicolamontecchio/d273802d6264fa33a715 to your computer and use it in GitHub Desktop.
# 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