How to check if multiple items from a list appear in a string?
<p>Let's say I have a list of keywords:</p>

<pre><code>keywords = ["history terms","history words","history vocab","history words terms","history vocab words","science list","science terms vocab","math terms words vocab"]
</code></pre>

<p>And a list of main terms:</p>

<pre><code>`main_terms = ["terms","words","vocab","list"]`
</code></pre>

<p>UPDATED to more clearly state the problem:</p>

<p>The script I'm making is to remove near-duplicates from a long list of keywords. I've managed to remove misspellings and slight variants (ex. "hitsory terms", "history term").</p>

<p><strong>My problem</strong> is that I have multiple terms that I'm looking for in this list of keywords, but after I've found one of these terms in a keyword (ex. "history terms") all keywords that are identical except with a different term or combination of terms (ex. "history vocab", "history words", "history words terms", etc.) should be considered duplicates.</p>

<ul>
<li>It is OK to have multiple terms in the keyword (ex. "math terms words vocab") <strong>as long as</strong> there is not a keyword that is identical save for having a lower number of the terms (ex. "math terms words" or ideally a single term like "math vocab").</li>
</ul>

<p>EDIT: I'm increasingly thinking you're asking an <a href="http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem">XY Question</a> and you want unique subjects.</p>

<p>If that is the case, the following works even better:</p>

<pre><code>result = []
found = []
for word in keywords:
    for term in main_terms:
        if term in word:
            word = word.replace(term, "")
    result.append(word.strip())

print set(result)
</code></pre>

<p>Which outputs <code>set(['science', 'math', 'history'])</code></p>

<hr>

<p>This solves your original problem with the same results, but does it by ignoring terms after the first and only passing unique first words.</p>

<pre><code>result = []
found = []
for word in keywords:
    found = False
    for res in result:
        if word.split()[0] in res:
            found = True
    if not found:
        result.append(word)
print result
</code></pre>

<p>See the demo on <a href="https://repl.it/Dbb1/0" rel="nofollow">repl.it</a></p>

python