python given two lists, find out how they are the same elements and different elements?

And a list such as list b, then for the same element 1, 2,3,4,5,6 different elements

= A [. 1, 2,. 3,. 4] 

B = [. 1,. 5,. 6]

1. Bitwise
Print (SET (A) & SET (B)) 

Print (SET (A) ^ SET (B)) XOR #

2 listing derived formula
same = [x for x in a if x in b]

print(same)

diff = [y for y in (a + b) if y not in same]

print(diff)

Guess you like

Origin www.cnblogs.com/newlangwen/p/12668783.html