python-collection set

set: itself is not hashable, but the elements in the set must be hashable and
non-hashable cannot be used as a dictionary key

set update:
s.add('asdf')
s.update(' asdf') s.remove(
'a')
s.pop()#randomly delete
s.clear()#clear the elements in s, the set s is still retained
del s# delete set s, keep nothing

a = set([1,2,3,4,5])
b = set([4,5,6,7,8])
a.intersection(b) #the intersection element of a and b, a & b
a .union(b) #union elements of a and b, a | b
a.difference(b)#difference in a but not in b, a - b
a.symmetric_difference(b)#symmetric difference/reverse intersection not in (a.intersection(b)), a ^ b

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325291689&siteId=291194637