Python兩個 list 獲取交集,並集,差集的方法

python兩個 list 獲取交集,並集,差集的方法 1. 獲取兩個list 的交集/ 方法一: a=[2,3,4,5] b=[2,5,8] tmp = [j for j in a if j in b] #列表推導式求的兩個列表的交集 print(tmp) 方法二: print(list(set(a).intersection(set(b)))) # #列用集合的取交集方法 方法三: lst =
相關文章
相關標籤/搜索