In this python dictionary program, we will extract unique values from dictionary values.
Steps to solve the program
- Take a dictionary in the given format as input and create an empty dictionary.
- Use for loop to iterate over the values in the dictionaries.
- Use a nested for loop to iterate the value list.
- If the element in the value list is not in the empty list then add that element to it using the append() function.
- Print the output.
D1= {'sqa':[1,2,5,6],'tools':[3,8,9],'is':[2,5,0],'best':[3,6,8]}
value = []
for val in D1.values():
for ele in val:
if ele not in value:
value.append(ele)
print(value)
[1, 2, 5, 6, 3, 8, 9, 0]