

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 – Filter all uppercase characters from given list of tuples
When it is required to filter all the uppercase characters from a list of tuples, a simple iteration, a Boolean value, the ‘append’ method and the ‘isupper’ methods are used.
Example
Below is a demonstration of the same −
my_list = [("PYTHON", "IS", "Fun"), ("PYTHON", "COOl"), ("PYTHON", ), "ORIENTED", "OBJECT"] print("The list is : " ) print(my_list) my_result_list = [] for sub_list in my_list: my_result = True for element in sub_list: if not element.isupper(): my_result = False break if my_result: my_result_list.append(sub_list) print("The resultant list is : ") print(my_result_list)
Output
The list is : [('PYTHON', 'IS', 'Fun'), ('PYTHON', 'COOl'), ('PYTHON',), 'ORIENTED', 'OBJECT'] The resultant list is : [('PYTHON',), 'ORIENTED', 'OBJECT']
Explanation
A list of tuples is defined and is displayed on the console.
An empty list is defined.
The original list is iterated over, and a Boolean value is set to ‘True’.
The list is again iterated and every element is checked to belong to upper case.
If not, the Boolean value is set to False.
The control breaks out of the loop.
Based on the Boolean value, the element is appended to the empty list.
This list is displayed as output on the console.
- Related Questions & Answers
- Python – Filter Tuples with Strings of specific characters
- Filter Tuples by Kth element from List in Python
- Remove tuples having duplicate first value from given list of tuples in Python
- Python – Strings with all given List characters
- Find the tuples containing the given element from a list of tuples in Python
- Remove duplicate tuples from list of tuples in Python
- Python Program – Strings with all given List characters
- Filter tuples according to list element presence in Python
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Remove tuples from list of tuples if greater than n in Python
- Python – Filter Tuples with Integers
- Python – Filter unique valued tuples
- Python – Filter consecutive elements Tuples
- Python program to replace all Characters of a List except the given character
- Combining tuples in list of tuples in Python
Advertisements