Checking what's missing from a list by comparing it to another python list

advertisements

I am looking to see what is missing from a list (A) from list (B)

If I have the following list of strings:

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

A = [4-5,3-6,3-3, 9-0] B = [4-4, 4-5, 3-3, 6-9, 5-5, 3-6, 3-2, 6-6, 9-9, 9,0]

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

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

Thanks!

I t hought about doing something like:

unique = []
for n in A:
    if n not in B:
        unique.append(B)
print(unique)

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


I don't know what 4-5 means? is it a string, an operation?

Anyways, assuming it is whatever you meant it to be you can do as follows:

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]

a = set(A)
b = set(B)

print b - a