
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python – Dictionaries with Unique Value Lists
When it is required to get the dictionaries with unique value lists, the ‘set’ operator and the list methods are used, along with a simple iteration.
Example
Below is a demonstration of the same −
my_dictionary = [{'Python' : 11, 'is' : 22}, {'fun' : 11, 'to' : 33}, {'learn' : 22},{'object':9},{'oriented':11}] print("The dictionary is : " ) print(my_dictionary) my_result = list(set(value for element in my_dictionary for value in element.values())) print("The resultant list is : ") print(my_result) print("The resultant list after sorting is : ") my_result.sort() print(my_result)
Output
The dictionary is : [{'Python': 11, 'is': 22}, {'fun': 11, 'to': 33}, {'learn': 22}, {'object': 9}, {'oriented': 11}] The resultant list is : [33, 11, 22, 9] The resultant list after sorting is : [9, 11, 22, 33]
Explanation
A list of dictionary is defined and is displayed on the console.
The values in the dictionary are accessed by iterating over, and converted to a set.
This way, the unique elements are obtained.
It is then converted to a list, and assigned to a variable.
It is displayed as the output on the console.
It is again sorted and displayed on the console.
- Related Articles
- Sort Python Dictionaries by Key or Value
- Python Program to get all unique keys from a List of Dictionaries
- Python – Remove Dictionaries with Matching Values
- Python – Filter dictionaries with ordered values
- Python – Merge Dictionaries List with duplicate Keys
- How to perform Calculations with Dictionaries in Python?
- Python – Cross mapping of Two dictionary value lists
- Python – Extract dictionaries with values sum greater than K
- Python – Sort Dictionaries by Size
- Assign value to unique number in list in Python
- Python - Unique keys count for Value in Tuple List
- How To Do Math With Lists in python ?
- What are Ordered dictionaries in Python?
- Handling missing keys in Python dictionaries
- Python program to merge two Dictionaries

Advertisements