- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
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)
The list is : [(14, 15, 19), (-32, 23, 32), (-31, 15, 63), (46, 68)] The result is : [(14, 15, 19), (46, 68)]
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.
- 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
- Combining tuples in list of tuples in Python
- 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
- Count tuples occurrence in list of tuples in Python
- Find top K frequent elements from a list of tuples in Python
- Remove duplicate tuples from list of tuples in Python
- Find the tuples containing the given element from a list of tuples in Python
- Python program to sort a list of tuples alphabetically
- Find Dissimilar Elements in Tuples in Python
- Python - Change the signs of elements of tuples in a list
- Python program to convert a list of tuples into Dictionary
- Convert list of tuples to list of list in Python
- Python program to Order Tuples using external List