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
๐ŸŒ
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

Discussions

python - How to check if a string is a substring of items in a list of strings - Stack Overflow
Copymy_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456'] for item in my_list: if 'abc' in item: print(item) ... Save this answer. ... Show activity on this post. Use the __contains__() method of Pythons string class.: 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
Help!: Check if a Python list item contains a string inside another string but with conditions
Here's two possibilities. If the way you get it done isn't important, you could use a regex because writing string parsing code is always sorta annoying. The regex [aeiou]*[f][aeiou]* would work I think. It matches any number of vowels, then a single "f", and then any number of vowels again. There's also another option. You have two conditions. It seems you want a single "f", which can be checked via word.count("f") == 1 and that every letter (excluding the "f") be a vowel. Essentially, every letter should pass letter == "f" or letter in "aeiou". To check every letter, you can utilize the built-in Python functionall(...). Checking that both these conditions hold, you should get the desired result. More on reddit.com
๐ŸŒ r/learnpython
6
1
January 13, 2021
Check contain string, and move the rest element to new list
I have a question related to a specific string being moved to new list. IF I have list like [โ€œhelloโ€, โ€œworldโ€, โ€œ====โ€,โ€œmyโ€, โ€œnameโ€,โ€œisโ€,โ€œXXXโ€], After โ€œ====โ€, the rest of the element will append to a new list so there are two new lists, listnew1 will store => ... More on discuss.python.org
๐ŸŒ discuss.python.org
11
0
February 2, 2023
๐ŸŒ
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 split() method breaks the string into individual words and sets are created from the string and list elements. The & operator computes the intersection of the two sets to check for common elements. Regular expressions provide flexibility for more complex matching scenarios but are less efficient for simple tasks. ... import re s = "Python is powerful and versatile." el = ["powerful", "versatile", "fast"] # Compile a regular expression pattern to search for any of the elements in the list pattern = re.compile('|'.join(map(re.escape, el))) res = bool(pattern.search(s)) print(res)
๐ŸŒ
Linux Hint
linuxhint.com โ€บ check-string-contains-substring-list-python
Linux Hint โ€“ Linux Hint
May 12, 2023 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
๐ŸŒ
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 - Hello is in the string Python is not in the string World is in the string ยท List comprehension is a concise way to create lists based on existing lists. It can also be used to perform operations on each element in a list. Link: For more information on list comprehension, check out our more comprehensive guide: ... 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.
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ python-check-if-string-contains-element-from-list
Check if a String contains an Element from a List in Python | bobbyhadz
Copied!my_list = ['BOBBY', 'HADZ', 'COM'] substring = 'z' result = any(substring.lower() in word.lower() for word in my_list) print(result) # ๐Ÿ‘‰๏ธ True if any(substring.lower() in word.lower() for word in my_list): # ๐Ÿ‘‡๏ธ this runs print('The substring is contained in at least one of the list items') else: print('The substring is NOT contained in any of the list items') The str.lower method returns a copy of the string with all the cased characters converted to lowercase. The method doesn't change the original string, it returns a new string. Strings are immutable in Python.
Find elsewhere
๐ŸŒ
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:
๐ŸŒ
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 โ€บ python list contains string
How to Check if List Contains a String in Python | Delft Stack
February 2, 2024 - In the above code, the if statement is used inside the for loop to search for strings containing a in the list py_list . Another list named new_list is created to store those specific strings. List comprehension is a way to create new lists based on the existing list. It offers a shorter syntax being more compact and faster than the other functions and loops used for creating a list.
๐ŸŒ
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)?

๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ help!: check if a python list item contains a string inside another string but with conditions
r/learnpython on Reddit: Help!: Check if a Python list item contains a string inside another string but with conditions
January 13, 2021 -

I have two days learning python but I really need to do that code. I also posted this question in StackOverflow but it got downvoted the first second.

I want to make a function to print all the words that contain a specific consonant (only one) and any amount of vowels, but I don't know how to introduce the conditions here.

I made a list with 4 elements via the input method (I know I use a different way), and a method that prints all the words that include the letter "f", but as I said, it needs to be more specific (only one consonant, "f" in this case, and any amount of vowels):

list = []  
for x in range (4):     
    words = str(input("Type a word "))     
    list.append(words)  

#This method kinda works, but it needs to be more specific.   
matching = [s for s in list if "f" in s] 
print(matching) 

In my code, if I have words with the letter "f", I'll get a list with all the words containing any amount of "f" letters and any other consonant, but I just want one consonant "f" and vowels, not the other consonants.

My desired result is like

list = [fox, alfa, fa, real, fou]

#['fa', 'fou']

๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Check contain string, and move the rest element to new list - Python Help - Discussions on Python.org
February 2, 2023 - I have a question related to a specific string being moved to new list. IF I have list like [โ€œhelloโ€, โ€œworldโ€, โ€œ====โ€,โ€œmyโ€, โ€œnameโ€,โ€œisโ€,โ€œXXXโ€], After โ€œ====โ€, the rest of the element will append to a new list so there are two new lists, listnew1 will store => ...
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-check-if-a-list-contains-a-string-in-python-559525
How to Check If a List Contains a String in Python | LabEx
In this step, you will learn how to use the any() function in combination with the isinstance() function to check if any element in a list is an instance of a specific data type, such as a string.
๐ŸŒ
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.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to check if a python string contains an element from a list
5 Best Ways to Check if a Python String Contains an Element from a List - Be on the Right Side of Change
February 26, 2024 - This code defines a function contains_substring() that takes a string and a list of elements as parameters. It loops through the list, and for each element, checks if it is present in the string using the in keyword.
๐ŸŒ
Quora
quora.com โ€บ How-do-I-check-if-a-string-is-in-a-list-in-Python
How to check if a string is in a list in Python - Quora
Answer (1 of 2): How do I check if a string is in a list in Python? You can do it with a conditional โ€˜ifโ€™ statement in this way: [code]# List of string listOfStrings = ['Hi' , 'hello', 'at', 'this', 'there', 'from'] if 'at' in listOfStrings : print("Yes, 'at' found in List : " , listOfString...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ python-check-if-array-or-list-contains-element-or-value
Python: Check if Array/List Contains Element/Value
February 27, 2023 - We can use a lambda function here to check for our 'Bird' string in the animals list. Then, we wrap the results in a list() since the filter() method returns a filter object, not the results. If we pack the filter object in a list, it'll contain the elements left after filtering:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-find-the-string-in-a-list
Python program to find String in a List - GeeksforGeeks
July 23, 2025 - The 'in' operator is the simplest and fastest way to check if a string exists in a list. It is efficient and widely used for this purpose. ... a = ['Learn', 'Python', 'With', 'GFG'] if 'Python' in a: print("String found!") else: print("String ...