- 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 - Find all the strings that are substrings to the given list of strings
When it is required to find all the strings that are substrings of a given list of strings, the ‘set’ and ‘list’ attributes are used.
Below is a demonstration of the same
my_list_1 = ["Hi", "there", "how", "are", "you"] my_list_2 = ["Hi", "there", "how", "have", "you", 'been'] print("The first list is :") print(my_list_1) print("The second list is :") print(my_list_2) my_result = list(set([elem_1 for subset_1 in my_list_1 for elem_1 in my_list_2 if elem_1 in subset_1])) print("The result is :") print(my_result)
The first list is : ['Hi', 'there', 'how', 'are', 'you'] The second list is : ['Hi', 'there', 'how', 'have', 'you', 'been'] The result is : ['there', 'you', 'Hi', 'how']
Two list of strings are defined and they are displayed on the console.
The two lists are iterated over, and ‘set’ attribute is used to get the unique values from the lists.
This is now converted into a list.
This is assigned to a variable.
This is the output that is displayed on the console.
- Program to find out the substrings of given strings at given positions in a set of all possible substrings in python
- Python – Strings with all given List characters
- Program to find size of common special substrings of two given strings in Python
- Python Program – Strings with all given List characters
- Python – All occurrences of Substring from the list of strings
- Python program – All occurrences of Substring from the list of strings
- Find all distinct palindromic sub-strings of a given String in Python
- Python – Find the sum of Length of Strings at given indices
- Find substrings that contain all vowels in Python
- Find all palindromic sub-strings of a given string - Set 2 in Python
- Converting all strings in list to integers in Python
- Python – Sort given list of strings by part the numeric part of string
- C program to find permutations of given strings
- Count strings that end with the given pattern in C++
- Check if all the palindromic sub-strings are of odd lengths in Python