Set characteristics : disorder , Do not modify the , Self weight removal , So you can set() Defining data as a set can achieve the function of de duplication .
a={1,3,2,2,3}
print(a)
b=[1,1,3,3,2,2]
print(set(b))
Return results :
{1, 2, 3}
{1, 2, 3}
a={1,2,3}
a.discard(1) # Delete the specified value
a.add(4) # New value added
b = a.pop() # Randomly delete and return
print(a,b)
Return results :
{3, 4} 2
a={1,2,3}
b={3,4,5}
print(a.union(b)) # Union
print(a.intersection(b)) # Find the intersection
print(a.difference(b)) # Difference set ,a Yes b No,
print(a.symmetric_difference(b)) # Eliminate intersection
print(a.issubset(b)) # Judge a yes b Subset
print(a.issuperset(b)) # Judge a yes b A set of parent
Return results :
{1, 2, 3, 4, 5}
{3}
{1, 2}
{1, 2, 4, 5}
False
False