Created
December 15, 2013 20:39
-
-
Save tkmru/7977826 to your computer and use it in GitHub Desktop.
dict.setdefault(key, default) is if key in dict: return dict[key] else: dict[key] = default return default
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
def group_by(dictionary): | |
d = {} | |
for k, v in dictionary.iteritems(): | |
d.setdefault(k, []).append(v) | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment