- 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 – Filter Similar Case Strings
When it is required to filter similar case strings, list comprehension can be used along with ‘isupper’ and ‘islower’ methods.
Below is a demonstration of the same
my_list = ["Python", "good", "FOr", "few", "CODERS"] print("The list is :") print(my_list) my_result = [sub for sub in my_list if sub.islower() or sub.isupper()] print("The strings with same case are :") print(my_result)
The list is : ['Python', 'good', 'FOr', 'few', 'CODERS'] The strings with same case are : ['good', 'few', 'CODERS']
A list is defined and is displayed on the console.
The list comprehension is used to iterate over the list and check if the strings are lower case or upper case.
This result is assigned to a variable.
This is displayed as output on the console.
- Python - Filter Supersequence Strings
- Python – Filter Strings within ASCII range
- Python – Filter rows without Space Strings
- K-Similar Strings in C++
- Python – Sort Strings by Case difference
- Python – Filter Tuples with Strings of specific characters
- Convert case of elements in a list of strings in Python
- Program to find smallest value of K for K-Similar Strings in Python
- How MySQL NULLIF() control flow function is similar to CASE statement?
- Filter in Python