python 求两个list的差集、并集与交集

1.差集

a = [1,2,3]
b = [2,3]
c = list(set(b).difference(set(a)))  # b中有而a中没有的

 

2 .并集

c = list(set(a).union(set(b)))

 

3.交集

c=list(set(a).intersection(set(b)))

 

posted @ 2020-06-05 11:51  踏叶乘风  阅读(833)  评论(0)    收藏  举报