Skip to content

Instantly share code, notes, and snippets.

@mrocklin
Last active December 17, 2015 13:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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