python取两个list的交集并集差集

a = [2,3,4,5,6,7]
b = [3,4,5,7,9]
tmp = [var for var in a if var in b]
print tmp
print list(set(a).union(set(b)))
print list(set(b).difference(set(a)))

你可能感兴趣的:(python取两个list的交集并集差集)