- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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.
Kickstart Your Career
Get certified by completing the courseGet Started