
- 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 program to find Tuples with positive elements in a List of tuples
When it is required to find tuples with positive elements in a list of tuples, list comprehension and ‘all’ operator is used.
Example
Below is a demonstration of the same −
my_tuple = [(14, 15, 19), (-32, 23, 32), (-31, 15, 63), (46, 68)] print("The list is :") print(my_tuple) my_result = [sub for sub in my_tuple if all(element >= 0 for element in sub)] print("The result is :") print(my_result)
Output
The list is : [(14, 15, 19), (-32, 23, 32), (-31, 15, 63), (46, 68)] The result is : [(14, 15, 19), (46, 68)]
Explanation
A list of tuple of integers is defined and is displayed on the console.
A list comprehension is used to iterate over the elements and check if element is greater than 0.
This is done using ‘all’ operator and is converted to a list.
This is assigned to a variable.
This is the output that is displayed on the console.
- Related Articles
- Python program to find Tuples with positive elements in List of tuples
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python program to convert elements in a list of Tuples to Float
- Python program to Convert a elements in a list of Tuples to Float
- Combining tuples in list of tuples in Python
- Find top K frequent elements from a list of tuples in Python
- Count tuples occurrence in list of tuples in Python
- Python program to sort a list of tuples alphabetically
- Remove duplicate tuples from list of tuples in Python
- Find the tuples containing the given element from a list of tuples in Python
- Python - Change the signs of elements of tuples in a list
- Python program to convert a list of tuples into Dictionary
- Find Dissimilar Elements in Tuples in Python
- Python – Extract tuples with elements in Range
- Python program to Order Tuples using external List

Advertisements