In this python dictionary program, we will remove duplicate values from Dictionary.
Steps to solve the program
- Take a dictionary as input and create an empty dictionary and list.
- Use for loop to iterate over keys and values of the dictionary using dictionary.items().
- If the value is not in the list then add that value and its key to the empty dictionary.
- Print the output.
dict1 = {'a':12,'b':2,'c':12,'d':5,'e':35,'f':5}
dict2 = {}
for key,val in dict1.items():
if val not in dict2.values():
dict2[key] = val
print(dict2)
Output :
{'a': 12, 'b': 2, 'd': 5, 'e': 35}