python兩個列表計算交集,並集,差集

獲取兩個list 的交集 #方法一: a=[2,3,4,5] b=[2,5,8] tmp = [val for val in a if val in b] print tmp #方法二 print list(set(a).intersection(set(b))) 獲取兩個list 的並集 print list(set(a).union(set(b))) 獲取兩個 list 的差集 print
相關文章
相關標籤/搜索