python得到兩個數組交集、並集、差集的方法

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