python数组交集、并集与不同

来源:互联网 发布:在线模拟装机软件 编辑:程序博客网 时间:2024/05/21 08:39
>>> a = [1,2,3]
>>> b = [2,4,5]
>>> list(set(a).intersection(set(b)))
[2]
>>> list(set(a).union(set(b)))
[1, 2, 3, 4, 5]
>>> list(set(a).difference(set(b)))
[1, 3]
>>> list(set(b).difference(set(a)))
[4, 5]
>>>
0 0