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.
extensionsToCheck = ('.pdf', '.doc', '.xls')
'test.doc'.endswith(extensionsToCheck) # returns True
'test.jpg'.endswith(extensionsToCheck) # returns False
all() stops at the first item evaluates to False. Basically:
if all(isinstance(x, (int, float)) for x in my_list):
print("all numbers!")
else:
print("not all number!")
And using these C-level functions instead of comprehensions should be more performant:
from itertools import repeat
if all(map(isinstance, my_list, repeat((int, float)))):
print("all numbers!")
else:
print("not all number!")
I can't think of any other way to check a sequence than to check the sequence whether you do it explicitly with a for loop, or implicitly with a higher level construct. Given that, you might consider something like this if your intent is to "end the program" upon finding a non-numeric value in the list as stated.
Example:
my_list = [1,2,3,4,6,7,"8"]
for value in my_list:
if not isinstance(value, (int, float)):
raise TypeError(f"Expected only numeric types, found {type(value)} in sequence.")
Output:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-791ea7c7a43e> in <module>
3 for value in my_list:
4 if not isinstance(value, (int, float)):
----> 5 raise TypeError(f"Expected only numeric types, found {type(value)} in sequence.")
TypeError: Expected only numeric types, found <class 'str'> in sequence.