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)
From this code I would expect to get a True value. If the word was "der", then the output should be False.
However, the result is a generator function, and I can't find a way to get the True value.
Any idea?
wordlist/worldlist). I'm guessing you forgot theany()call when you tried it before.any.ipython --pylab, which "helpfully" imports * from numpy for you. In that case you can directly use__builtin__.anywithout having to import__builtin__like in Ashwini's answer, since__builtin__shows up in interactive shells automatically. Also @DSM: apparently the behavior ofnumpy.anychanged (for the worse) in 1.7.