title: How to find an exact sequence of words in lists using Python 3?
body: <p>I am coding in Python 3 on a Windows platform.</p>
  
  <p>I am making a function that will pass in a user's inputted sentence which my function will then <code>.split()</code> and make it a list of each word that was in their original sentence.</p>
  
  <p>My function will also pass in a predefined list of word patterns that my function will be watching for as a match on the exact sequence of words appearing in the user's sentence.</p>
  
  <p>Now just so this is clear, I already can use <code>.intersection()</code> to find where the exact words are matches <strong>but I am looking for an exact sequence of words</strong>.</p>
  
  <p>For instance if my user inputs: <code>"I love hairy cats"</code>, and the predefined list of key words is something like this: <code>["I love", "hairy cats", "I love cats", "love hair"]</code>, my function should only indicate <code>"I love"</code> and <code>"hairy cats"</code> as these two matched the specified sequence of words as they appeared in the predefined lists.</p>
  
  <p>Here is my code thus far:</p>
  
  <pre><code>def parse_text(message, keywords):
      newList = []
      Message = message.split()
      Keywords = keywords      # Keywords need to be a list type
      setMessage = set(word for word in Message)
      setKeywords = set(word for word in Keywords)
      newList = setMessage.intersection(setKeywords)
  
      return newList
  </code></pre>
  
  <p>This works perfectly so far only if my keywords list contains only single words. My issue is when I try to make my list with multiple words to denote the sequence.</p>
  
  <p>If my user's original message is:</p>
  
  <pre><code>message = "Hello world, yes and no"
  
  keywords = ["help", "Hello", "yes", "so"]  # this works, intersec "Hello" and "yes"
  
  keywords = ["help me", "Hello mom", "yes and no", "so"]  # this does not work, just returns empty "set()"
  </code></pre>
  
  <p>Any ideas of how I can make adjustments to my function to check my user's original sentence for a specific sequence of words as they appear my keyword list?</p>