A dictionary contains the pair of the keys & values (represents key : value), a dictionary is created by providing the elements within the curly braces ({}), separated by the commas.
In a dictionary, the keys need to be unique but the values mapped can have duplicate values.
Here, we need to print all the unique values from the dictionary.
We have a dictionary consisting of key-value pairs, with duplicate values. We will print all the unique values from the dictionary.
Example:
Dictionary =
['scala':1, 'Javascript': 7, 'Python':1, 'C++':5, 'Java':3]
Unique values =
1, 7, 5, 3
To find all the unique values, we will extract all the values of the dictionary. Then to find unique values, we will use set comprehension. And store the unique values to a list using list().
Program to extract unique values from the dictionary
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer