python里的数组的布尔运算

小白发言:
python里面咋对数组进行布尔运算嘞?
比如a=【1,2,3,5】,b=【1,2,3,4】,分别求a和b的交集A∩B=[1,2,3],并集A∪B=[1,2,3,4,5]、补集A-B=[5]

  1. 获取两个list 的交集
    print list(set(a).intersection(set(b)))

  2. 获取两个list 的并集
    print list(set(a).union(set(b)))

  3. 获取两个 list 的差集
    print list(set(b).difference(set(a))) # b中有而a中没有的


可以看下python参考手册中的 python-布尔运算 --- and, or, not