Skip to content

Instantly share code, notes, and snippets.

@mrocklin
Last active December 17, 2015 13:39
Show Gist options
  • Save mrocklin/5618992 to your computer and use it in GitHub Desktop.
Save mrocklin/5618992 to your computer and use it in GitHub Desktop.
# Passes https://gist.github.com/mrocklin/5722155
def groupby(f, coll):
""" Group elements in collection by ``f`` """
d = dict()
for item in coll:
key = f(item)
if key not in d:
d[key] = []
d[key].append(item)
return d
@eigenhombre
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment