Skip to content

Instantly share code, notes, and snippets.

@tknhs
Created February 19, 2014 16:15
Show Gist options
  • Save tknhs/9095364 to your computer and use it in GitHub Desktop.
Save tknhs/9095364 to your computer and use it in GitHub Desktop.
Extract the duplicate values from dictionary
from collections import Counter
my_dict = {'F': 200, 'G': 500, 'D': 100, 'E': 400, 'B': 200, 'C': 300, 'A': 500}
# duplicate values list
dup_list = [k for k, v in Counter(my_dict.values()).items() if v > 1] # [200, 500]
print({k: v for k, v in my_dict.items() if v in dup_list}) # {'F': 200, 'G': 500, 'B': 200, 'A': 500}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment