title: Python if any() does not work
body: <p>I want to check if any string elements in a list <code>phrases</code> contains certain keywords in a set <code>phd_words</code>. I want to use <code>any</code> but it doesn't work.</p>
  
  <pre><code>In[19]:
      import pandas as pd
      import psycopg2 as pg
  
      def test():
      phd_words = set(['doctor', 'phd'])
      phrases = ['master of science','mechanical engineering']
      for word in phrases:
          if any(keyword in word for keyword in phd_words):
              return 'bingo!'
  
  test()
  
  Out[20]: 
    bingo!
  </code></pre>
  
  <p>How should I fix this?</p>