Try this test:

any(substring in string for substring in substring_list)

It will return True if any of the substrings in substring_list is contained in string.

Note that there is a Python analogue of Marc Gravell's answer in the linked question:

from itertools import imap
any(imap(string.__contains__, substring_list)) 

In Python 3, you can use map directly instead:

any(map(string.__contains__, substring_list))

Probably the above version using a generator expression is more clear though.

Answer from Sven Marnach on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-test-if-string-contains-element-from-list
Python - Test if string contains element from list - GeeksforGeeks
July 11, 2025 - The re.compile() function compiles the pattern for faster matching and search checks for its presence in the string. This method is less efficient for simple substring checks due to overhead from compiling patterns.
Discussions

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 detect if a string contains a substring of a list (or dictionary)
You are currently checking whether z is a substring of any element of my_list. I think you want to check whether any element of my_list is a substring of z (also, the if is a little redundant, since any already gives a boolean value): def chek(z): return any(s in z for s in my_list) Might also be worth using lower on z before the check to ignore differences in capitalisation if you aren't already doing that (and assuming the elements in my_list are all lower-case). More on reddit.com
🌐 r/learnpython
5
22
July 13, 2021
(Python) How to check if an element in a string is a part of a Tuple/List?

I don't know what you mean by "an element in a string," as a string doesn't consist of smaller elements. Do you mean how to check whether a particular value is an element in a list/tuple?

  1. https://www.google.com/search?q=python%20list%20include

  2. http://stackoverflow.com/questions/7571635/fastest-way-to-check-if-a-value-exist-in-a-list

More on reddit.com
🌐 r/learnprogramming
30
6
June 6, 2015
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
🌐
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)?

🌐
Real Python
realpython.com › python-string-contains-substring
How to Check if a Python String Contains a Substring – Real Python
September 10, 2025 - By calling .group() and specifying that you want the first capturing group, you picked the word secret without the punctuation from each matched substring. You can go into much more detail with your substring matching when you use regular expressions. Instead of just checking whether a string contains another string, you can search for substrings according to elaborate conditions. Note: If you want to learn more about using capturing groups and composing more complex regex patterns, then you can dig deeper into regular expressions in Python.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-check-if-string-contains-another-string
How To Check If a String Contains Another String in Python | DigitalOcean
Learn how to check if one string contains another in Python using in, find(), and regular expressions. Explore common pitfalls, and efficient practices.
🌐
Stack Abuse
stackabuse.com › bytes › check-if-a-string-contains-an-element-from-a-list-in-python
Check if a String Contains an Element from a List in Python
October 6, 2023 - In our case, we can use list comprehension to create a new list that contains the elements from my_list that are found in my_string. Here's how to do it: ... No spam ever. Unsubscribe anytime. Read our Privacy Policy. my_string = "Hello, World!" my_list = ["Hello", "Python", "World"] found_elements = [element for element in my_list if element in my_string] print(found_elements)
🌐
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.
Find elsewhere
🌐
ReqBin
reqbin.com › code › python › wzo2s8ib › python-string-contains-example
How to check if a string contains a substring in Python?
December 20, 2022 - To check if a Python string contains the desired substring, you can use the "in" operator or the string.find() 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))
🌐
Udemy
blog.udemy.com › home › it & development › software development › the many ways to check if a python string contains a substring
Ways to Check if a Python String Contains a Substring - Udemy Blog
April 14, 2026 - This operator is actually just shorthand for the contains method of the Python string class. Using it will call this method to determine if a substring exists in the string in question. You should at least be familiar with this operator because you can also use it to check if an element exists in a tuple, array, or list...
🌐
Programiz
programiz.com › python-programming › examples
Python Examples | Programiz
Python Program to Check if a Key is Already Present in a Dictionary · Python Program to Split a List Into Evenly Sized Chunks · Python Program to Parse a String to a Float or Int · Python Program to Print Colored Text to the Terminal · Python Program to Convert String to Datetime · Python Program to Get the Last Element of the List · Python Program to Get a Substring of a String ·
🌐
PYnative
pynative.com › home › python exercises › python basic exercise for beginners: 40 coding problems with solutions
Python Basic Exercise for Beginners: 40 Coding Problems with Solutions
February 8, 2026 - ... Iterate through the string using a for loop. For each character, use the built-in .isdigit() method. If you find even one digit, you can set a flag to True and break the loop. ... user_input = "Python3" contains_digit = False # Iterate through each character for char in user_input: if ...
🌐
Playwright
playwright.dev › assertions
Assertions | Playwright
Playwright includes test assertions in the form of expect function. To make an assertion, call expect(value) and choose a matcher that reflects the expectation. There are many generic matchers like toEqual, toContain, toBeTruthy that can be used to assert any conditions · Playwright also includes ...
🌐
Python
docs.python.org › 3 › builtins › stdtypes.html
Built-in Types — Python 3.14.7 documentation
To check if sub is a substring or not, use the in operator: ... Perform a string formatting operation. The string on which this method is called can contain literal text or replacement fields delimited by braces {}. Each replacement field contains ...
🌐
Python Engineer
python-engineer.com › posts › check-if-string-contains-substring
How to check if a String contains a Substring in Python - Python Engineer
However, to check if a string contains a substring, you can simply use the if x in my_string syntax: my_string = "Hello World" if "World" in my_string: print("has substring") This check is case sensitive!
🌐
Python Guides
pythonguides.com › check-if-a-python-string-contains-a-substring
How to Check if a Python String Contains a Substring
January 5, 2026 - Learn how to check if a Python string contains a substring using the 'in' operator, find(), index(), and regex with real-world USA-based data examples.
🌐
jq
jqlang.org › manual
jq 1.8 Manual
A string B is contained in a string A if B is a substring of A. An array B is contained in an array A if all elements in B are contained in any element in A. An object B is contained in object A if all of the values in B are contained in the ...
🌐
iO Flood
ioflood.com › blog › python-string-contains
Python String Contains | Methods and Usage Examples
December 5, 2023 - Whether you’re a beginner just starting out or an experienced programmer looking for advanced techniques, this comprehensive guide is your roadmap to mastering the art of finding substrings in Python. You can use the in keyword in Python to ...
🌐
datagy
datagy.io › home › python posts › python strings › python string contains: check if a string contains a substring
Python String Contains: Check if a String Contains a Substring • datagy
December 16, 2022 - In order to do this, we can use a for loop to loop over each item in the list to check if it contains a substring. If it does, then we append it to another list. ... # Using a For Loop to Filter a List of Strings strings = ['hello and welcome', ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-if-string-contains-substring-in-python
Check if String Contains Substring in Python - GeeksforGeeks
December 20, 2025 - The index() method works similarly ... you need the exact position of the substring and want an explicit error if it’s missing. ... If 'Kingdom' does not exist, it raises a ValueError. Python - Test if string contains element from list...