-1

If List A= [1,2] and List B=[2,4]

I want the difference between A and B which is present in B.

that is, diff between A and B is [1,4]... should be present in B... SO the final output should be C=[4]

2 Answers2

0

use sets()

A = {1,2}
B = {2, 4}

print(B.difference(A)) 
or
print(B - A)
KayseMca
  • 40
  • 1
  • 6
0

Using the XOR ^ operator in set:

lst_A = [1,2]
lst_B = [2,4]

print(list(set(lst_A) ^ set(lst_B)))

OUTPUT:

[1,4]
DirtyBit
  • 16,613
  • 4
  • 34
  • 55