
- 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 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 Articles
- Python – Filter Tuples with Strings of specific characters
- Filter Tuples by Kth element from List in Python
- Python – Strings with all given List characters
- Remove tuples having duplicate first value from given list of tuples in Python
- Python Program – Strings with all given List characters
- Find the tuples containing the given element from a list of tuples in Python
- Filter tuples according to list element presence in Python
- Remove duplicate tuples from list of tuples in Python
- Python program to find tuples which have all elements divisible by K from a list of tuples
- 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
- Remove tuples from list of tuples if greater than n in Python
- Python | Remove empty tuples from a list

Advertisements