-1

I want to compare two lists and extract unmatched values.

Example:

list1 = ['A1', 'B1', 'C1', 'D1', 'E1']

list2 = ['A1', 'B1', 'D1', 'E1']

so the 'C1' is not in list 2 so I want output as

output: C1
zabop
  • 5,493
  • 3
  • 23
  • 56

1 Answers1

0

you can use the symmetric_difference for sets:

set(list1) ^ set(list2)
# {'C1'}

depending on what you really need, you may need the difference

set(list1) - set(list2)
# {'C1'}
hiro protagonist
  • 40,708
  • 13
  • 78
  • 98