Diff'ing a mixed lists
<p>Forgive me if this is a stupid question, I've done my best to look this up with no success, and I am by no means a Python expert.</p>

<p>I was writing some stuff to "diff" two lists:  basically, compare 2 lists and fill a third list with the common values, while removing them from the original two lists.  So I wrote this:</p>

<pre><code>list_1 = ["dog", "cat", "bird", "rabbit", "rabbit"]
list_2 = ["fly", "monkey", "bird", "rabbit", "bear", "rabbit"]
matches = []

for thing in list_1:
    while thing in list_2:
        list_1.pop(list_1.index(thing))
        popper = list_2.pop(list_2.index(thing))
        matches.append(popper)
</code></pre>

<p>Which gets me:</p>

<pre><code>list_1:
['dog', 'cat']
list_2:
['fly', 'monkey', 'bear']
Matches:
['bird', 'rabbit', 'rabbit']
</code></pre>

<p>That's exactly what I'd expect/want... "rabbit" shows up twice since it's in both lists twice.</p>

<p>But then using the same for loop, this:</p>

<pre><code>list_1 = ["dog", "cat", ["bird", "rabbit"], "rabbit"]
list_2 = ["fly", "monkey", ["bird", "rabbit"], "bear", "rabbit"]
</code></pre>

<p>gets me:</p>

<pre><code>list_1:
['dog', 'cat', 'rabbit']
list_2:
['fly', 'monkey', 'bear', 'rabbit']
Matches:
[['bird', 'rabbit']]
</code></pre>

<p>The second "rabbit" isn't getting added to the matches list, and it remains in the originals. What is going on here that I'm not getting?</p>
