码迷,mamicode.com
首页 > 编程语言 > 详细

python 集合

时间:2018-02-21 12:21:35      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:python   diff   markdown   div   union   log   blog   集合   intersect   

a = set([1,2,3,4])
b = set([3,4,5,6])

print(a.intersection(b)) # 交集 {3, 4}
print(a.union(b))   # 并集 {1, 2, 3, 4, 5, 6}
print(a.difference(b)) # 差集 in a but not in b {1, 2}
print(b.difference(a)) # 差集 in b but not in a {5, 6}
print(a.symmetric_difference(b)) # 对称 差集 {1, 2, 5, 6}

python 集合

标签:python   diff   markdown   div   union   log   blog   集合   intersect   

原文地址:https://www.cnblogs.com/ihitao/p/8456382.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!