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 - List comprehension is a concise way to filter and create a new list by applying a condition to each element. It is a popular method for its readability and ease of use. ... a = ['GeeksforGeeks', 'Geeky', 'Computers', 'Algorithms'] b = 'Geek' # Substring res = [i for i in a if b in i] print(res)
Discussions

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
How to find all occurrences of a substring in a string while ignore some characters in Python?
You could use re for this. ex import re long_string = 'this is a t`es"t. Does the test work?' small_string = "test" chars_to_ignore = ['"', '`'] print(re.findall(f"[{''.join(chars_to_ignore)}]*".join(small_string), long_string)) More on reddit.com
🌐 r/learnpython
6
1
July 25, 2024
How can I find all exact occurrences of a string, or close matches of it, in a longer string in Python?
This is a regex operation. You can match exact with some_substring in full_string Then find the index. But partial matches is going to require a lot of code or a regex expression. More on reddit.com
🌐 r/learnpython
8
1
May 9, 2024
Replace substrings with dictionary values in order
So there are multiple ways to solve this, but doing it with a dictionary is a bit tricky. It's doable, I'd probably try a nested dictionary and iterating over the strings character by character, but you'd probably find a 2D tuple with a loop easier. Or regex. More on reddit.com
🌐 r/learnpython
16
1
January 7, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › python › create-list-of-substrings-from-list-of-strings-in-python
Create List of Substrings from List of Strings in Python - GeeksforGeeks
July 23, 2025 - In this example, a list comprehension is employed to create a new list, `substring_list`, containing substrings extracted from each string in the `original_list`. The slicing notation `[s[1:4] for s in original_list]` extracts characters from ...
🌐
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

🌐
IONOS
ionos.com › digital guide › websites › web development › python substring
How to create and edit Python substrings - IONOS
July 19, 2023 - The substring function can also be used to extract Python sub­strings. The syntax for this function is similar to the slice function syntax: ... If you want to see multiple Python sub­strings instead of just one at a time, you can use Python splits. With this function, you can specify a separator to create a Python list of sub­strings.
🌐
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.
🌐
Python Examples
pythonexamples.org › python-check-if-string-contains-substring-from-list
Python - Check if String contains Substring from List
source_string = 'a b c d e f' list_of_strings = ['k', 'm', 'e' ] for substring in list_of_strings: if substring in source_string: print('String contains substring from list.') break
🌐
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 lambda function returns True if the substring is found in the item, thus filtering out the rest. The result is converted back to a list. The output shows ‘banana’, which is the only item containing ‘an’. This method is particularly useful when you want to apply more complex conditions or when working with larger datasets. For more complex string matching scenarios, Python’s re module provides powerful tools through regular expressions.
Find elsewhere
🌐
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 - In this article, we will explore five simple and commonly used methods to extract substrings from a list of strings in Python.
🌐
AskPython
askpython.com › python › list › find-string-in-list-python
Find a string in a List in Python - AskPython
February 16, 2023 - We can use a list comprehension to find all elements in the list that contain the substring “Hello“. The syntax is as follows:
🌐
Pluralsight
pluralsight.com › blog › software development
6 Best Methods for Python String to List Conversion | Pluralsight
String slicing is a popular method to extract substrings from a string. Combining it with list comprehension can convert a string to a list.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-the-substring-from-given-string-using-list-slicing
Python | Get the substring from given string using list slicing - GeeksforGeeks
July 11, 2025 - initial_strings : xbzefdgstb print resultant substring from start xb print resultant substring from end efdgstb · Example 2: In this example, we will see how to create a string by taking characters from a certain positional gap. ... # Python3 code to demonstrate # to create a substring from string # Initialising string ini_string = 'xbzefdgstb' # printing initial string and character print("initial_strings : ", ini_string) # creating substring by taking element # after certain position gap # define length upto which substring required sstring_alt = ini_string[::2] sstring_gap2 = ini_string[::3] # printing result print("print resultant substring from start", sstring_alt) print("print resultant substring from end", sstring_gap2)
🌐
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 is similar to the list comprehension approach, but instead of creating a separate list, it uses a generator expression within the any() function directly. In this example, we are using the generator expression (substring in string for string in string_list) which generates a sequence of Boolean values indicating if the substring is present in each string.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-all-occurrences-of-substring-in-string
Python - All occurrences of substring in string - GeeksforGeeks
July 12, 2025 - List comprehension with range() can be used to generate all starting positions of a substring by iterating over the string indices. It checks each possible position within the string to see if the substring matches starting from that index. Python · s = "hello world, hello universe" substring = "hello" # Find all occurrences using list comprehension positions = [i for i in range(len(s)) if s.startswith(substring, i)] print(positions) Output ·
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-substring
Python String Substring | DigitalOcean
August 4, 2022 - In this tutorial, we will look into various operations related to substrings. Let’s first look at two different ways to create a substring. We can create a substring using string slicing. We can use split() function to create a list of substrings based on specified delimiter.
🌐
Codecademy
codecademy.com › article › how-to-check-if-a-string-contains-a-substring-in-python
How to Check if a String Contains a Substring in Python | Codecademy
Since the substring is present in the string and it starts from index 17, the code produces this output: ... Let’s move on to the next method on the list, which is the Python .contains() method.
🌐
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 - The original string is : ['GeeksforGeeks', 'is', 'Best'] Is check string part of any input list string : True ... # Python3 code to demonstrate working of # Check if substring is part of List of Strings # initializing list test_list = ['GeeksforGeeks', 'is', 'Best'] # test string check_str = "for" # printing original string print("The original string is : " + str(test_list)) res=False # Check if substring is part of List of Strings for i in test_list: if(i.find(check_str)!=-1): res=True # printing result print("Is check string part of any input list string : " + str(res))
🌐
datagy
datagy.io › home › python posts › python strings › python: find an index (or all) of a substring in a string
Python: Find an Index (or all) of a Substring in a String • datagy
December 20, 2022 - We get a list returned of all the instances where that substring occurs in our string · In the final section of this tutorial, you’ll learn how to build a custom function to return the indices of all substrings in our Python string.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-substring-a-string-in-python
How to Substring a String in Python - GeeksforGeeks
July 23, 2025 - Python · # code str = &quot;GeeksForGeeks is best!&quot; substring = str[14:16] print(substring) Output · is · We can use the split() function to get the substrings.The split() method effectively splits the string "Geeks For Geeks" into words ...
🌐
Edureka
edureka.co › blog › substring-in-python
Everything You Need to Know about Substring in Python | Edureka
November 28, 2024 - # Slicing or substring a string using positive index. s= 'PYTHON' s[0:3] Output: ‘PYT’ · Retrieving all substrings using list comprehension