0

I have two list

ListA = ['John', 'Glucose', 'ABC', 'XYZ'....]
ListB = ['XYZ', 'John', 'Mike',.....]
num = []
for i in range(len(ListB)):
    for a in range(len(ListA)):
        if ListB[i] == ListA[a]:
            print(a)
            num.append(a)
num = sorted(num)
print(ListA[POINT OF DIFFERENCE UPON OBSERVATION])

These list are not the same length or contain all the same strings.

I would like to print out a list containing the names of the components that are missing each of the listA and ListB: An output that would be helpful would be

List A missing Gabriel and Bob. List B missing Fructose and Xylem.

Right now I have half the solution. If someone could guide my reasoning that would be helpful.

Thank you

glibdud
  • 7,550
  • 4
  • 27
  • 37
user9995331
  • 155
  • 5
  • Use the set difference of both. `set(listA) - set(listB)`, etc. – user3483203 Jul 09 '18 at 18:19
  • Consider reading a little about [set theory](https://en.wikipedia.org/wiki/Set_theory#Basic_concepts_and_notation) and the reason why this works will become clear. –  Jul 09 '18 at 18:25

1 Answers1

1

Use sets:

set_A = set(ListA)
set_B = set(ListB)

print(set_A - set_B)
print(set_B - set_A)
nosklo
  • 217,122
  • 57
  • 293
  • 297