
- 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 – Filter unique valued tuples
When it is required to filter unique valued tuples from a list of tuples, the ‘list’ and ‘set’ methods are used.
Example
Below is a demonstration of the same −
my_list = [(42, 51), (46, 71), (14, 25), (26, 91), (56, 0), (11, 1), (99,102)] print("The list of tuple is :") print(my_list) my_list.sort() print("The list after sorting is :") print(my_list) my_result = list(set(my_list)) print("The result is :") print(my_result)
Output
The list of tuple is : [(42, 51), (46, 71), (14, 25), (26, 91), (56, 0), (11, 1), (99, 102)] The list after sorting is : [(11, 1), (14, 25), (26, 91), (42, 51), (46, 71), (56, 0), (99, 102)] The result is : [(11, 1), (26, 91), (42, 51), (46, 71), (56, 0), (14, 25), (99, 102)]
Explanation
A list of tuple of integers is defined and is displayed on the console.
It is sorted using the ‘sort’ method.
This is displayed on the console.
It is converted to a set to get the unique values, and then to a list.
This result is assigned to a variable.
This is the output that is displayed on the console.
- Related Articles
- Python – Filter Tuples with Integers
- Python – Filter consecutive elements Tuples
- Python – Filter Tuples Product greater than K
- Python – Filter Tuples with Strings of specific characters
- Filter Tuples by Kth element from List in Python
- Filter tuples according to list element presence in Python
- Python – Filter all uppercase characters from given list of tuples
- Filter unique array values and sum in JavaScript
- How to split Python tuples into sub-tuples?
- Combining tuples in list of tuples in Python
- Count tuples occurrence in list of tuples in Python
- How to Concatenate tuples to nested tuples in Python
- Remove duplicate tuples from list of tuples in Python
- Filter in Python
- Updating Tuples in Python

Advertisements