- 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 Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
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.
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)
The list is : [('PYTHON', 'IS', 'Fun'), ('PYTHON', 'COOl'), ('PYTHON',), 'ORIENTED', 'OBJECT'] The resultant list is : [('PYTHON',), 'ORIENTED', 'OBJECT']
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