Checking WHAT is missing from a list when comparing it to another list python
<p>I am looking to see what is missing from a list (A) from list (B)</p>

<p>If I have the following list of strings:</p>

<p><code>A = ['4-5', '3-6', '3-3', '9-0']</code> and <code>B = ['4-4', '4-5', '3-3', '6-9', '5-5', '3-2', '6-6', '9-9', '9,0']</code> and want to check what is missing from A that is in list B. </p>

<p>A = [<strong>4-5</strong>,<strong>3-6</strong>,<strong>3-3</strong>, <strong>9-0</strong>] 
B = [4-4, <strong>4-5</strong>, <strong>3-3</strong>, 6-9, 5-5, <strong>3-6</strong>, 3-2, 6-6, 9-9, <strong>9,0</strong>]</p>

<p>so... from the example from above, I would want it to output <code>['4-4', '6-9', '5-5', '3-2', '6-6', '9-9']</code>.</p>

<p>if I sort both the lists, what's the best way of going about it?</p>

<p>Thanks!</p>

<p>I t hought about doing something like:</p>

<pre><code>unique = []
for n in A:
    if n not in B:
        unique.append(B)
print(unique)
</code></pre>

<p>does this work? it's giving me a very odd output of a list in a list of two strings.</p>

<p>Don't bother sorting. Use sets instead and calculate the difference:</p>

<pre><code>A = ['4-5','3-6','3-3', '9-0']
B = ['4-4', '4-5', '3-3', '6-9', '5-5', '3-2', '6-6', '9-9', '9','0']

print(set(B) - set(A))
&gt;&gt; {'0', '6-9', '9-9', '5-5', '3-2', '6-6', '4-4', '9'}
</code></pre>

<p>Your required out put was <code>[4-4, 6-9, 5-5, 3-2, 6-6, 9-9]</code>. You either missed a few, or you meant to treat <code>'9'</code> as <code>'9-0'</code>.</p>

python list sorting