
- 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 Supersequence Strings
When it is required to filter supersequence strings, a simple list comprehension is used.
Example
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)
Output
The list is : ['Python', '/', 'is', 'alwaysgreat', 'to', 'learn'] The resultant string is : ['alwaysgreat']
Explanation
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.
- Related Articles
- 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
- JavaScript filter array by multiple strings?
- Program to find length of shortest supersequence in Python
- Shortest Common Supersequence in C++
- Filter in Python
- JavaScript filter an array of strings, matching case insensitive substring?
- Example filter() in python
- Python – Filter Sorted Rows
- What is filter() in python?
- Python – Filter Tuples with Integers
- Python – Filter unique valued tuples
- Python – Filter consecutive elements Tuples

Advertisements