007python路--集合
集合set
去重
a = [1,2,3,2,] #传入集合的只能是字符串,列表,元组。
a = set(a) #得到去重的集合
集合关系
set('hello') == set('helloasd')
set('hello') != set('helloasd')
print( set('hello') < set('hello world') ) #属于True
set('hello') <= set('hello')
---------------------------------------------------------------
a = set([1,2,3,4,5,]) b = set([4,5,6,7,])
交集 a & b
并集 a | b
差集 a - b
对称差集 a^b #{1, 2, 3, 6, 7}
s = ['asd']
a = set(s)
增
a.update( [12 , 'eee'] ) #{'asd' ,'eee', } #元组/列表
删
s.remove(内容)
s.clear()
del s

浙公网安备 33010602011771号