Merged Sort Algorithm
<p>I have a merge algorithm which is really fast: it's currently set up to check unknown words between lists; this function checks common words, I need to change the function below to check if words are in vocab or wds or neither I don't properly understand the function so any comments about what specific lines do would be great.</p>

<p>def find_unknowns_merge_pattern(vocab, wds):</p>

<pre><code>result = []
xi = 0
yi = 0

while True:
    if xi &gt;= len(vocab):
        result.extend(wds[yi:])
        return result

    if yi &gt;= len(wds):
        return result

    if vocab[xi] == wds[yi]:  # Good, word exists in vocab
        yi += 1

    elif vocab[xi] &lt; wds[yi]: # Move past this vocab word,
        xi += 1

    else:                     # Got word that is not in vocab
        result.append(wds[yi])
        yi += 1
</code></pre>

<p>def check(bigger_vocab,book_words):</p>

<pre><code>    both = [ ]
        for words in bigger_vocab:
            for people in book_words:
                if words == people:
                    words.split()
                    both.append(words)

    return both
</code></pre>

<p>The problem is it takes at least 5 seconds whereas my merge algorithm takes 0.08. How can I call that function so I can make this one faster?</p>

<p>Are you just trying to find words that appear in bigger_vocab and book_words? If so:</p>

<pre><code>both = list(set(bigger_vocab).intersection(book_words))
</code></pre>

python