-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
  • 6,750
  • 3
  • 39
  • 84

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
  • 44,693
  • 14
  • 86
  • 111