title: python - string match only whole words
body: <p>I have two lists - <code>query</code> and <code>line</code>. My code finds if a <code>query</code> such as:</p>
  
  <pre><code>["president" ,"publicly"]
  </code></pre>
  
  <p>Is contained in a <code>line</code> (order matters) such as:</p>
  
  <pre><code>["president" ,"publicly", "told"]
  </code></pre>
  
  <p>And this is the code I'm currently using:</p>
  
  <pre><code>if ' '.join(query) in ' '.join(line)
  </code></pre>
  
  <p>Problem is, I want to match whole words only. So the query below won't pass the condition statement:</p>
  
  <pre><code>["president" ,"pub"]
  </code></pre>
  
  <p>How can I do that?</p>