Last active
December 17, 2015 13:39
-
-
Save mrocklin/5618992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1