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>Simple!</p>

<p>We can iterate over the good_synonyms list and check if <em>any</em> of them are present in the input string.</p>

<pre><code>if any(synonym in status for synonym in good_synonyms):
    print('That is good')
else:
    print('That is not so good')
</code></pre>

<p>PS: To save memory, you could perhaps store the synonyms only in lower-case, as ['good', 'well'], and when you check if these are in the 'status' variable, you could just apply the .lower() on it, which just converts the entire string into lower-case, as:</p>

<pre><code>good_synonyms = ['good', 'well']
if any(synonym in status.lower() for synonym in good_synonyms):
     print('That is good')
</code></pre>

<p>Hope this helps!</p>

<p><strong>Note</strong>: holdenweb's answer works too, but applying the split function on status isn't really required as you can check whether a word is present in a string(provided the words in the string are separated by a space) or not using the 'in' keyword as described above.</p>

python