I know I can do:
if 'hello' in 'hello world':
What if I have a several needles like ('.css', '.js', '.jpg', '.gif', '.png', '.com') and I want to check if either of these is in a string.
(note: endswith won't do it in this case, they may not be suffixes)
You may find any useful:
haystack = 'hello world'
needles = ['.css', '.js', '.jpg', '.gif', '.png', '.com']
if any(needle in haystack for needle in needles):
pass # ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With