Created
February 10, 2015 10:53
-
-
Save embayer/ea7c2bccfb7f3e3217e4 to your computer and use it in GitHub Desktop.
find duplicated values in a python dict
This file contains hidden or 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
| base_dict = {"a": "python", "b": "python", "c": "swift"} | |
| # build a reversed multidict (values becomes keys, keys become (tuple) key(s) | |
| rev_multidict = {} | |
| for key, value in base_dict.iteritems(): | |
| rev_multidict.setdefault(value, set()).add(key) | |
| for key, value in rev_multidict.iteritems(): | |
| if len(value) > 1: | |
| # item with duplicated value (key) | |
| # list(value) # to access |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment