Skip to content

Instantly share code, notes, and snippets.

@ruda
Last active June 13, 2016 02:09
Show Gist options
  • Save ruda/5239383bb84aaf1abf1a312717b633fa to your computer and use it in GitHub Desktop.
Save ruda/5239383bb84aaf1abf1a312717b633fa to your computer and use it in GitHub Desktop.
Split iterable in group of 'n' values and yield these values.
def nsplit(iterable, n):
result = []
for i, x in enumerate(iterable, 1):
result.append(x)
if i % n == 0:
yield result
result = []
if result:
yield result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment