print [s for s in list if sub in s]

If you want them separated by newlines:

print "\n".join(s for s in list if sub in s)

Full example, with case insensitivity:

mylist = ['abc123', 'def456', 'ghi789', 'ABC987', 'aBc654']
sub = 'abc'

print "\n".join(s for s in mylist if sub.lower() in s.lower())
Answer from David Robinson on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-finding-strings-with-given-substring-in-list
Finding Strings with Given Substring in List - Python - GeeksforGeeks
July 11, 2025 - When combined with a lambda function, it becomes an elegant way to find strings containing a specific substring. ... a = ['GeeksforGeeks', 'Geeky', 'Computers', 'Algorithms'] b = 'Geek' # Substring res = list(filter(lambda x: b in x, a)) print(res) ... Explanation: filter() check if the substring b is in each string of the list a, returning an iterator of matching strings, which is then converted to a list and stored in res.
Discussions

python - How to check if a string is a substring of items in a list of strings - Stack Overflow
How do I search for items that contain the string 'abc' in the following list? xs = ['abc-123', 'def-456', 'ghi-789', 'abc-456'] The following checks if 'abc' is in the list, but does not detect '... More on stackoverflow.com
🌐 stackoverflow.com
How do I check if string contains all substrings in list?

You could try

if all([val in string for val in list]):

Which checks the truth of each check and returns True only if all are True. Otherwise you're looking at a loop (or if your lists get really big a generator).

More on reddit.com
🌐 r/learnpython
11
1
November 16, 2018
How to check if any element in a list contains a substring
If you don't need to know exactly which element(s) contain the substring, then you could use the any built-in function in combination with a list comprehension l = ["Hey dude", "Hey bro", "Sup dude", "Hey bud"] substring = "Sup" if any([substring in element for element in l]): print(f"One or more elements of {l} contain the substring {substring}") else: print(f"No elements of {l} contain the substring {substring}") Here's an explanation about the any function. Alternatively, switch out any for all if you want to check if all the elements of the list contain the substring. all documentation More on reddit.com
🌐 r/learnpython
18
11
October 28, 2019
Find the most common substring in list of strings
Maybe I'm missing your point, but it looks like the most common set amongst the strings in your example is "the real" as it is (I think?) the only one in all four. Just making sure I understand your goal here. More on reddit.com
🌐 r/learnpython
5
0
February 23, 2022
🌐
Reddit
reddit.com › r/learnpython › how to check if any element in a list contains a substring
r/learnpython on Reddit: How to check if any element in a list contains a substring
October 28, 2019 -

Say I have a list of strings like: ["Hey dude", "Hey bro", "Sup dude", "Hey bud"]

How do I check if *any* of those strings in the list contain the word "Sup"?Alternatively, in my case, I could also check if *all* of the strings contain "Hey" , which I also don't know how to do.

(Sorry, I'm new to Python)

Edit: Thank you so much for all the help, guys <3

🌐
DigitalOcean
digitalocean.com › community › tutorials › python-find-string-in-list
Python Find String in List: Methods and Examples | DigitalOcean
1 month ago - A common point of confusion is that in on a list checks for an exact match, when you may just want to know whether any element contains a target substring. The following patterns solve this and let you choose the result you need: the matching elements, a True/False answer, or just the first match. Use a list comprehension with the in operator (which does check for substrings inside individual strings) to collect every element that contains the target text:
🌐
AskPython
askpython.com › python › list › find-string-in-list-python
Find a string in a List in Python - AskPython
February 16, 2023 - Let’s take another case, where you wish to only check if the string is a part of another word on the list and return all such words where your word is a sub-string of the list item. List comprehensions can be a useful tool to find substrings in a list of strings.
Find elsewhere
🌐
CodeSignal
codesignal.com › learn › courses › practicing-string-operations-and-type-conversions-in-python › lessons › exploring-substring-search-in-python-strings
Exploring Substring Search in Python Strings
We're to identify all occurrences of each substring within its corresponding original string and return a list of the starting indices of these occurrences. Remember, index counting should start from 0. ... If we take the following lists: Original List: ["HelloWorld", "LearningPython", "GoForBroke", "BackToBasics"] Substring List: ["loW", "ear", "o", "Ba"].
🌐
Delft Stack
delftstack.com › home › howto › python › find elements with specific substring
How to Find String in List in Python | Delft Stack
March 11, 2025 - The output includes ‘apple’, ... effective methods for finding strings in lists using Python: list comprehension, the filter() function, and regular expressions....
🌐
YouTube
youtube.com › watch
How to Search for a Substring in a List of Strings using python? #python #pythontutorial #howto - YouTube
Lets learn How to Search for a Substring in a List of Strings using python?Web Development Playlist: https://www.youtube.com/playlist?list=PLPrnFIEBKtbZCXwIV...
Published   October 21, 2023
🌐
TutorialsPoint
tutorialspoint.com › article › python-find-all-the-strings-that-are-substrings-to-the-given-list-of-strings
Python - Find all the strings that are substrings to the given list of strings
March 26, 2026 - This approach checks if each string from one list appears as a substring in any string from another list ? main_strings = ["Hello", "there", "how", "are", "you"] search_strings = ["Hi", "there", "how", "have", "you", "been"] print("Main strings:", main_strings) print("Search strings:", search_strings) # Find strings from search_strings that are substrings of any string in main_strings result = list(set([search_str for main_str in main_strings for search_str in search_strings if search_str in main_str])) print("Substrings found:", result)
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-find-all-the-strings-that-are-substrings-to-the-given-list-of-strings
Python - Find all the strings that are substrings to the given list of strings - GeeksforGeeks
April 21, 2023 - In this, any() is used to check for substring matching in any of the strings from the string list to be matched in. ... # Python3 code to demonstrate working of # Substring Intersections # Using any() + generator expression # initializing lists ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-check-if-substring-is-part-of-list-of-strings
Python | Check if substring is part of List of Strings - GeeksforGeeks
May 3, 2023 - Method #1 : Using join() The basic approach that can be employed to perform this particular task is computing the join of all the list strings and then searching the string in the joined string.
🌐
Python Examples
pythonexamples.org › python-check-if-string-contains-substring-from-list
Python - Check if String contains Substring from List
To check if string contains substring from a list of strings in Python, iterate over list of strings, and for each item in the list, check if the item is present in the given string.
🌐
W3docs
w3docs.com › python
How to check if a string is a substring of items in a list of strings
def is_substring(string, string_list): for item in string_list: if string in item: return True return False string_list = ["hello", "world", "goodbye"] print(is_substring("wor", string_list)) # True print(is_substring("dog", string_list)) # False ...
🌐
Reddit
reddit.com › r/learnpython › how do i check if string contains all substrings in list?
r/learnpython on Reddit: How do I check if string contains all substrings in list?
November 16, 2018 -

I have a list, that takes inputs from the user, this means it can change size; for example: list = ["test", "do"] or list = ["a", "b", "c"]

I want to check if variable string, contains all the substrings in list.

I thought if I used:

if list in string: that would work, but it didn't, TypeError: 'in <string>' requires string as left operand, not list

Is there another function/method for this? Or am I going to have to loop len(list) times (I really don't want to do that, because I check hundreds of changing strings)?

🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to find all occurrences of a substring in a list of strings with python
5 Best Ways to Find All Occurrences of a Substring in a List of Strings with Python - Be on the Right Side of Change
March 5, 2024 - By employing a list comprehension, this snippet not only checks for the presence of the substring using the in operator but also calls the find() method on the string to obtain the exact starting position of the substring. Regular expressions provide a powerful way to search for patterns. By using Python’s re module, you can find complex patterns within strings.
🌐
TutorialsPoint
tutorialspoint.com › how-to-check-if-a-substring-is-a-part-of-list-of-strings-using-python
How to Check if a substring is a part of List of Strings using Python?
August 7, 2023 - This approach involves iterating over each string in the list and checking if the substring is present in each string. In this example, we loop through each string in the list using a for loop. For each string, we use the in operator to check if the substring is present. If we find a match, ...
🌐
w3resource
w3resource.com › python-exercises › puzzles › python-programming-puzzles-16.php
Python: Find the strings in a list containing a given substring - w3resource
Write a Python program to find strings in a given list containing a given substring. Input: [(ca,('cat', 'car', 'fear', 'center'))] Output: ['cat', 'car'] Input: [(o,('cat', 'dog', 'shatter', 'donut', 'at', 'todo', ''))] Output: ['dog', 'donut', 'todo'] Input: [(oe,('cat', 'dog', 'shatter', 'donut', 'at', 'todo', ''))] Output: [] ... # Define a function named 'test' that takes a list of strings 'strs' and a substring 'substr' as input def test(strs, substr): # Use a list comprehension to filter strings in 'strs' that contain the given 'substr' return [s for s in strs if substr in s] # Create a
🌐
GeeksforGeeks
geeksforgeeks.org › python › extract-list-of-substrings-in-list-of-strings-in-python
Extract List of Substrings in List of Strings in Python - GeeksforGeeks
July 23, 2025 - List comprehension is a concise and powerful way to create lists in Python. It can be employed to extract substrings based on certain conditions or patterns. The following example demonstrates how to extract all substrings containing a specific keyword: ... string_list = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;date&quot;] keyword = &quot;an&quot; result = [substring for substring in string_list if keyword in substring] print(result)