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 - Explanation :re.findall() checks for occurrences of the substring b in each string of a. If a match is found, the string is included in the list 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
Python: How to check a string for substrings from a list? - Stack Overflow
How can I check a string for substrings contained in a list, like in Check if a string contains an element from a list (of strings), but in Python? 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
is string.find(substring) time complexity of O(n) or (O*m)?
It doesn't seem to be specified anywhere but I would expect it to be O(nร—m) where n is the length of string and m is the length of substring. More on reddit.com
๐ŸŒ r/cpp_questions
5
4
May 14, 2019
๐ŸŒ
IONOS
ionos.com โ€บ digital guide โ€บ websites โ€บ web development โ€บ python substring
How to create and edit Python substrings - IONOS
July 19, 2023 - Due to the blank space between the words, each word is now a substring. The subยญstrings are stored in the โ€œresultโ€ variable: [โ€˜Pythonโ€™, โ€˜isโ€™, โ€˜aโ€™, โ€˜popularโ€™, โ€˜language.โ€™]. You can also save Python subยญstrings in a list if you use a regular exยญpresยญsion on a string and then the findall function from the โ€œreโ€ library.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-get-all-substrings-of-given-string
Python - Get all substrings of given string - GeeksforGeeks
July 12, 2025 - Store substrings in a list: Each generated substring is appended to the substrings list for collection. itertools.combinations() function generates all possible combinations of a given length from an iterable. It is useful for generating substrings of a specific length by specifying the range of indices for each combination. ... import itertools # Define the input string s = "abc" # Get all substrings using combinations of indices substrings = [''.join(s[i:j]) for i, j in itertools.combinations(range(len(s) + 1), 2)] print(substrings)
๐ŸŒ
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 index 1 to 3 (exclusive) from each string in the original list.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-substring-a-string-in-python
How to Substring a String in Python - GeeksforGeeks
July 23, 2025 - We can use the split() function to get the substrings.The split() method effectively splits the string "Geeks For Geeks" into words based on spaces. So, the resulting substrings list contains each word as an element
Find elsewhere
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-string-substring
Python String Substring | DigitalOcean
August 4, 2022 - s = 'My Name is Pankaj' # create substring using slice name = s[11:] print(name) # list of substrings using split l1 = s.split() print(l1) ... We can use in operator or find() function to check if substring is present in the string or not.
๐ŸŒ
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 = ["apple", "banana", "cherry", "date"] keyword = "an" result = [substring for substring in string_list if keyword in substring] print(result)
๐ŸŒ
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

๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ extract a substring from a string in python
Extract a substring from a string in Python
2 weeks ago - Extract substrings from Python strings using slice notation with [start:end] indexes, or use re.search() with regex patterns for matching specific formats
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to get All Substrings of a String in Python With List Comprehensions! List Comprehension How To - YouTube
If you liked the content, please consider checking out my Patreon! - https://www.patreon.com/CodingUnderPressure/membership Hey everyone, today we are going ...
Published ย  October 9, 2021
๐ŸŒ
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
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ python string substring
Python String Substring - AskPython
August 6, 2022 - str = 'Engineering Discipline' sub1 = str[:3] sub2 = str[6:] print ("Resultant substring from the start: ", sub1) print ("Resultant substring from the end: ", sub2) ... from itertools import combinations str1 = "Safa" print("The original string ...
๐ŸŒ
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)?

๐ŸŒ
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-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.
๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ devops and development โ€บ how to substring a string in python
How to Substring a String in Python | phoenixNAP KB
November 27, 2025 - The resulting indexes are in a list. If there are no matches, the code returns an empty list. ... You've learned how to create and work with substrings in Python. String slicing and various built-in methods simplify working with substrings.