Program to remove duplicate values from dictionary values.

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

Steps to solve the program
  1. Take a dictionary as input and create an empty dictionary.
  2. Use for loop to iterate over keys and values of the dictionary.
  3. Use a nested for loop to iterate over the value list.
  4. Using an if statement check for duplicate values. 
  5. If any duplicate value exists then remove it from the value list using remove().
  6. Add the key and the value list to the empty dictionary.
  7. Print the output.
				
					dict1 = {'marks1':[23,28,23,69],'marks2':[ 25, 14, 25]}

for key,val in dict1.items():
    for ele in val:
        if ele in val:
            val.remove(ele)

print(dict1)
				
			

Output :

				
					{'marks1': [28, 69], 'marks2': [14, 56]}
				
			

remove a word from the string if it is a key in a dictionary.

check whether a dictionary is empty or not.

Leave a Comment