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>I'm sure there's a more elegant solution, but this seems to be the solution for which you're looking, at least for part 1):</p>

<pre><code>&gt;&gt;&gt; def remove_main_terms(keyword):
        words = keyword.split()
        count = 0
        to_keep = []
        for word in words:
            if word in main_terms:
                count += 1
            if count &lt; 2:
                to_keep.append(word)
            else:
                pass
        return " ".join(to_keep)

&gt;&gt;&gt; keywords = ["history terms","history words","history vocab","history words terms","history vocab words","science list","science terms vocab","math terms words vocab"]

&gt;&gt;&gt; main_terms = ["terms","words","vocab","list"]

&gt;&gt;&gt; new_list = []
&gt;&gt;&gt; for w in keywords:
        new_list.append(remove_main_terms(w))

&gt;&gt;&gt; new_list
['history terms', 'history words', 'history vocab', 'history words', 'history vocab', 'science list', 'science terms', 'math terms']
</code></pre>

python