Skip to content

Instantly share code, notes, and snippets.

@theredpea
Created March 3, 2014 19:49
Show Gist options
  • Save theredpea/9333154 to your computer and use it in GitHub Desktop.
Save theredpea/9333154 to your computer and use it in GitHub Desktop.
def groupBy(iterable, groupsize=3, strict=True):
if strict:
assert len(iterable)%groupsize == 0, 'Need evenly divisible'
return [iterable[_:_+groupsize] for _ in range(len(iterable))[::groupsize]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment