Skip to content

Instantly share code, notes, and snippets.

@embayer
Created February 10, 2015 10:53
Show Gist options
  • Select an option

  • Save embayer/ea7c2bccfb7f3e3217e4 to your computer and use it in GitHub Desktop.

Select an option

Save embayer/ea7c2bccfb7f3e3217e4 to your computer and use it in GitHub Desktop.
find duplicated values in a python dict
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