Use a generator together with any, which short-circuits on the first True:

if any(ext in url_string for ext in extensionsToCheck):
    print(url_string)

EDIT: I see this answer has been accepted by OP. Though my solution may be "good enough" solution to his particular problem, and is a good general way to check if any strings in a list are found in another string, keep in mind that this is all that this solution does. It does not care WHERE the string is found e.g. in the ending of the string. If this is important, as is often the case with urls, you should look to the answer of @Wladimir Palant, or you risk getting false positives.

Answer from Lauritz V. Thaulow on Stack Overflow
🌐
Data Science Parichay
datascienceparichay.com › home › blog › python – check if all elements in list are strings
Python - Check If All Elements in List are Strings - Data Science Parichay
October 7, 2022 - To check if all the elements in a given Python list are strings or not, use the all() function to check if each value in the list is of str type (using the insinstance() function).
🌐
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)?

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-test-if-string-contains-element-from-list
Python - Test if string contains element from list - GeeksforGeeks
July 11, 2025 - Testing if string contains an element from list is checking whether any of the individual items in a list appear within a given string. any() is the most efficient way to check if any element from the list is present in the list.
🌐
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

🌐
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 these scenarios, and many others, being able to check if a string contains an element from a list becomes important. The in operator in Python is used to check if a value exists in a sequence (like a string or a list).
Find elsewhere
🌐
Iditect
iditect.com › faq › python › how-to-check-if-all-items-in-list-are-string-in-python.html
How to check if all items in list are string in python
def all_string_elements(lst): return all(type(item) == str for item in lst) # Example usage: my_list = ["cat", "dog", "bird"] if all_string_elements(my_list): print("All elements in the list are of type string.") else: print("Not all elements in the list are of type string.") How to determine ...
🌐
w3resource
w3resource.com › python-exercises › list › python-data-type-list-exercise-201.php
Python: Check if a given string contains an element, which is present in a list - w3resource
November 3, 2023 - # For each 'el', check if it is present in the string 'str1'. result = [el for el in lst if (el in str1)] # Return a boolean indicating whether the 'result' list is not empty (i.e., if any element was found in the string). return bool(result) ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-find-string-in-list
Python Find String in List: Methods and Examples | DigitalOcean
Learn how to find a string in a Python list using in, index(), list comprehension, and regex. See practical, runnable code examples and start today.
🌐
Python Forum
python-forum.io › thread-39309.html
Checking if a string contains all or any elements of a list
January 29, 2023 - so i have some keywords in a list and i want to check if a string contains any or all of those keywords. E.g teststring = 'this is a test string it contains apple, orange & banana. Moreover, this i a
Top answer
1 of 7
6
str1 = "45892190"
lis = [89,90]

for i in lis:
    if str(i) in str1:
        print("The value " + str(i) + " is in the list")

OUTPUT:

The value 89 is in the list

The value 90 is in the list

If you want to check if all the values in lis are in str1, the code of cricket_007

all(str(l) in str1 for l in lis)
out: True

is what you are looking for

2 of 7
4

If no overlap is allowed, this problem becomes much harder than it looks at first. As far as I can tell, no other answer is correct (see test cases at the end).

Recursion is needed because if a substring appears more than once, using one occurence instead of the other could prevent other substrings to be found.

This answer uses two functions. The first one finds every occurence of a substring in a string and returns an iterator of strings where the substring has been replaced by a character which shouldn't appear in any substring.

The second function recursively checks if there's any way to find all the numbers in the string:

def find_each_and_replace_by(string, substring, separator='x'):
    """
    list(find_each_and_replace_by('8989', '89', 'x'))
    # ['x89', '89x']
    list(find_each_and_replace_by('9999', '99', 'x'))
    # ['x99', '9x9', '99x']
    list(find_each_and_replace_by('9999', '89', 'x'))
    # []
    """
    index = 0
    while True:
        index = string.find(substring, index)
        if index == -1:
            return
        yield string[:index] + separator + string[index + len(substring):]
        index += 1


def contains_all_without_overlap(string, numbers):
    """
    contains_all_without_overlap("45892190", [89, 90])
    # True
    contains_all_without_overlap("45892190", [89, 90, 4521])
    # False
    """
    if len(numbers) == 0:
        return True
    substrings = [str(number) for number in numbers]
    substring = substrings.pop()
    return any(contains_all_without_overlap(shorter_string, substrings)
               for shorter_string in find_each_and_replace_by(string, substring, 'x'))

Here are the test cases:

tests = [
    ("45892190", [89, 90], True),
    ("8990189290", [89, 90, 8990], True),
    ("123451234", [1234, 2345], True),
    ("123451234", [2345, 1234], True),
    ("123451234", [1234, 2346], False),
    ("123451234", [2346, 1234], False),
    ("45892190", [89, 90, 4521], False),
    ("890", [89, 90], False),
    ("8989", [89, 90], False),
    ("8989", [12, 34], False)
]

for string, numbers, should in tests:
    result = contains_all_without_overlap(string, numbers)
    if result == should:
        print("Correct answer for %-12r and %-14r (%s)" % (string, numbers, result))
    else:
        print("ERROR : %r and %r should return %r, not %r" %
              (string, numbers, should, result))

And the corresponding output:

Correct answer for '45892190'   and [89, 90]       (True)
Correct answer for '8990189290' and [89, 90, 8990] (True)
Correct answer for '123451234'  and [1234, 2345]   (True)
Correct answer for '123451234'  and [2345, 1234]   (True)
Correct answer for '123451234'  and [1234, 2346]   (False)
Correct answer for '123451234'  and [2346, 1234]   (False)
Correct answer for '45892190'   and [89, 90, 4521] (False)
Correct answer for '890'        and [89, 90]       (False)
Correct answer for '8989'       and [89, 90]       (False)
Correct answer for '8989'       and [12, 34]       (False)
🌐
TutorialsPoint
tutorialspoint.com › python-program-to-test-if-string-contains-element-from-list
Python program to find the String in a List
January 27, 2023 - The count() method is useful when you need to know how many times a string appears. List comprehension with any() provides flexibility for partial matching or custom conditions. Use the 'in' operator for simple exact string matching.
🌐
Delft Stack
delftstack.com › home › howto › python › python list contains string
How to Check if List Contains a String in Python | Delft Stack
February 2, 2024 - We can also use list comprehension to find out strings containing multiple specific values i.e., we can find strings containing a and b in py_list by combining the two comprehensions. ... py_list = ["a-1", "b-2", "c-3", "a-4", "b-8"] q = ["a", "b"] r = [s for s in py_list if any(xs in s for xs in q)] print(r) ... The filter() function filters the given iterable with the help of a function that checks whether each element satisfies some condition or not.