I have found some answers to this question before, but they seem to be obsolete for the current Python versions (or at least they don't work for me).
I want to check if a substring is contained in a list of strings. I only need the boolean result.
I found this solution:
word_to_check = 'or'
wordlist = ['yellow','orange','red']
result = any(word_to_check in word for word in worldlist)
You can import
__builtin__ in case it was replaced by some other
>>> from __builtin__ import any as b_any >>> lis= ['yellow', 'orange', 'red'] >>> word = "or" >>> b_any(word in x for x in lis) True
Noe that in Python 3
__builtin__ has been renamed to