Python program to print all the unique values in a dictionary.

In this python dictionary program, we will print all the unique values in a dictionary.

Steps to solve the program
  1. Take a list of dictionaries as input and create an empty list.
  2. Use a for loop to iterate over each dictionary in the list.
  3. Use a nested for loop to iterate over each dictionary value.
  4. If the value is not in the list that we have created, then add that value to the list using append().
  5. Print the output.
				
					list1 = [{'name1':'robert'},{'name2':'john'},{'name3':'jim'},
         {'name4':'robert'}]
list2 = []
for val in list1:
    for ele in val.values():
        if ele not in list2:
            list2.append(ele)
            
print(list2)
				
			

Output :

				
					['robert', 'john', 'jim']
				
			

add two dictionaries if the keys are the same then add their value.

display different combinations of letters from dictionary values.

Leave a Comment