What is efficient way to match words in string (Python)?
<p>Example:</p>

<pre><code>1. names = ['James John', 'Robert David', 'Paul' ... the list has 5K items]
2. 
3. text1 = 'I saw James today'
4. text2 = 'I saw James John today'
5. text3 = 'I met Paul'
6. 
7. is_name_in_text(text1,names)   # this returns false 'James' in not in list
8. is_name_in_text(text2,names)   # this returns 'James John'
9. is_name_in_text(text3,names)   # this return 'Paul'
</code></pre>

<p>is_name_in_text () searches if any of the name list is in text.</p>

<p>The easy way to do is to just check if the name is in the list by using '<code>in</code>' operator, but the list has 5,000 items, so it is not efficient. I can just split the text into words and check if the words are <code>in</code> the list, but this not going to work if you have more than one word matching. Line number 7 will fail in this case.</p>
