首页 > 编程语言 > 详细

python-集合set

时间:2018-05-05 14:04:50      阅读:213      评论:0      收藏:0      [点我收藏+]

set:本身非可哈希,但set里面元素必须可哈希
非可哈希不能作为字典的键

set更新:
s.add(‘asdf‘)
s.update(‘asdf‘)
s.remove(‘a‘)
s.pop()#随机删除
s.clear()#清空s中元素,集合s还保留
del s#删除集合s,什么都不保留

a = set([1,2,3,4,5])
b = set([4,5,6,7,8])
a.intersection(b) #a和b的交集元素, a & b
a.union(b) #a和b的并集元素, a | b
a.difference(b)#差集 in a but not in b, a - b
a.symmetric_difference(b)#对称差集/反向交集 not in (a.intersection(b)), a ^ b

a.issuperset(b)
a.issubset(b)

python-集合set

原文:https://www.cnblogs.com/benchdog/p/8994416.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!