- 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 Supersequence Strings
When it is required to filter supersequence strings, a simple list comprehension is used.
Below is a demonstration of the same
my_list = ["Python", "/", "is", "alwaysgreat", "to", "learn"] print("The list is :") print(my_list) substring = "ys" my_result = [sub for sub in my_list if all(elem in sub for elem in substring)] print("The resultant string is :") print(my_result)
The list is : ['Python', '/', 'is', 'alwaysgreat', 'to', 'learn'] The resultant string is : ['alwaysgreat']
A list is defined and is displayed on the console.
A substring is defined.
The list comprehension is used to iterate through the elements using the ‘all’ clause.
This is assigned to a variable.
This is the output that is displayed on the console.
- Python – Filter Similar Case Strings
- Python – Filter Strings within ASCII range
- Python – Filter rows without Space Strings
- Python – Filter Tuples with Strings of specific characters
- Program to find length of shortest supersequence in Python
- Shortest Common Supersequence in C++
- Filter in Python
- Example filter() in python
- What is filter() in python?
- Python – Filter Sorted Rows
- Lambda and filter in Python Examples
- Lambda and filter Examples in Python
- Python – Filter Tuples with Integers