Skip to content

Instantly share code, notes, and snippets.

@mrocklin

mrocklin/groupby.py

Last active Dec 17, 2015
Embed
What would you like to do?
# 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

This comment has been minimized.

Copy link

@eigenhombre eigenhombre commented Jun 6, 2013

+1

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