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>Simple in a list comprehension too. Not sure why you would sort the inputs, I don't see that it's really necessary, but I've sorted the output.</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'] 
new = sorted([x for x in B if x not in A])
</code></pre>

<p>though your expected output doesn't include the last two entries "9" and "0", or "9,0" depending on interpretation</p>

python list sorting