python-集合set

此页面是否是列表页或首页?未找到合适正文内容。

python-集合set

标签:字典asdupd随机enccticlear集合删除

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 & ba.union(b) #a和b的并集元素, a | ba.difference(b)#差集 in a but not in b, a – ba.symmetric_difference(b)#对称差集/反向交集 not in (a.intersection(b)), a ^ b

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

python-集合set

标签:字典asdupd随机enccticlear集合删除

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

作者: 安兔兔

为您推荐

返回顶部