python得到列表list的交集与差集

python 神勇,得到两个列表的差集和交集,根本不用循环,一句话就可以搞定

交集:

b1=[1,2,3]
b2=[2,3,4]
b3 = [val for val in b1 if val in b2]
print b3

差集:

b1=[1,2,3]
b2=[2,3,4]
b3 = [val for val in b1 if val not in b2]
print b3

原文地址:https://www.cnblogs.com/mingaixin/p/2864808.html