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>Loop through the <code>keywords</code> and check each one against the <code>main_terms</code>:</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"]
main_terms = {"terms","words","vocab","list"}
result = {}
for words in keywords:
    s = set(words.split())
    s_subject = s - main_terms
    subject = s_subject and next(iter(s_subject))
    if s | main_terms and subject and subject not in result:
        result[subject] = words
</code></pre>

<p>The turn the result values into a list:</p>

<pre><code>&gt;&gt;&gt; list(result.values())
['math terms words vocab', 'history terms', 'science list']
</code></pre>

python