Python program to remove duplicate values from Dictionary.

In this python dictionary program, we will remove duplicate values from Dictionary.

Steps to solve the program
  1. Take a dictionary as input and create an empty dictionary and list.
  2. Use for loop to iterate over keys and values of the dictionary using dictionary.items().
  3. If the value is not in the list then add that value and its key to the empty dictionary.
  4. 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}
				
			

clear all items from the dictionary.

create a dictionary from the string.

Leave a Comment