Python check if any part of string in list
<p>I have a list containing synonyms for the word 'Good' (this list here is shortened)</p>

<pre><code>good_synonym = ['Good','good','Well','well']
</code></pre>

<p>And the program asks how the user is feeling</p>

<pre><code>print = 'Hello, ' + name + ', How are you?'
status = raw_input('')
</code></pre>

<p>But sometimes, the user may respond to the question with "I am good" (or similar)</p>

<p>If the answer contains a word in the good synonym list, I want the program to reply</p>

<pre><code>if status contains a word in good_synonym:
    print ('That is good')
else:
    print ('That is not so good')
</code></pre>

<h1>note that the first line is not real python language</h1>

<p>But I don't know which phrase to use to do the action.</p>

<p>A short and simple solution would be to use regular expressions for pattern matching like this:</p>

<pre><code>import re

line = "it is good"
good_synonyms = ["good","well"]

line = line.lower()
if any(re.search(synonym,line) for synonym in good_synonyms):
    print "That is good"
else:
    print "nope"
</code></pre>

<p>The <code>search</code> function of <code>re</code> looks for a match of pattern anywhere in the string and returns a boolean which then can be used in an if statement with <code>any</code></p>

python