In this python dictionary program, we will print all the unique values in a dictionary.
Steps to solve the program
- Take a list of dictionaries as input and create an empty list.
- Use a for loop to iterate over each dictionary in the list.
- Use a nested for loop to iterate over each dictionary value.
- If the value is not in the list that we have created, then add that value to the list using append().
- 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']