(每天一句python)两个list的交集、并集、差集
直接上码:
一.两个list差集
ret = list(set(a) ^ set(b))
补一个常见方法:
ret = []
for i in a:
if i not in b:
ret.append(i)
二. 获取两个list 的并集
ret = list(set(a).union(set(b)))
三. 获取两个 list 的差集
# b中有而a中没有的
ret = list(set(b).difference(set(a)))