通过set()获取两个数组的交/并/差集:

print set(a) & set(b) # 交集, 等价于set(a).intersection(set(b))
print set(a) | set(b) # 并集, 等价于set(a).union(set(b))
print set(a) - set(b) # 差集,在a中但不在b中的元素, 等价于set(a).difference(set(b))
print set(b) - set(a) # 差集,在b中但不在a中的元素, 等价于set(b).difference(set(a))

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2021-10-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
相关资源
相似解决方案