The road to wudao-the three major days of the refining stage
Set (variable ):
Unique, unordered, set () is converted into a set, removing duplicates.
Setx = set ([,]), sety = set ))
Add: setx. add (), add an element to it, setx. update ([2, 4, 3]), and add all the elements in the list to it (the Set will de-duplicate)
Delete: setx. remove (element): specifies who to delete. It is the same as discard (). However, if discart does not change the element in the collection, no error is reported. If discart does not change the element, remove will, setx. pop () randomly deletes one
Some methods:
Whether in, not in is in the collection,
Setx. intersection (sety): calculates the intersection of the two sets. You can also write it as setx & sety, setx. isdisjoint (sety) to determine whether there is no intersection between the two sets. If there is no intersection, True is returned.
Setx. union (sety): returns the union of the two sets, which can be written as setx | sety
Setx. difference (sety): calculate the difference set of the Two sets (in setx and no longer the sety element). It can be written as setx-sety.
Setx. equalric_difference (sety) is used to calculate the symmetric difference set of the two sets. if not all the elements of the two sets are in the Union-intersection, it can be written as setx ^ sety
Setx. issubset (sety), whether setx is a subset of sety, and whether issuperset () is a parent set
Len (setx), set. clear ()