set
set的应用
- 找到list,file中的unique elements
- 找到various combinations of elements using the set operators.
Sets are unordered collections of unique items, just like mathematical sets.
Sets are specified by curly braces—like dictionaries, but there are no colons.
Common mathematical set operations are supported. For A = {'a','b','c','d'} and B = {'c','d','e','f'}:
- A.intersection(B) is {'c','d'}; shorthand: A & B
- A.union(B) is {'a','b','c','d'}; shorthand: {A | B}
- A.difference(B) is {'a','b'}; shorthand: A - B
- A.symmetric difference(B) is {'a','b','e','f'}; shorthand: AˆB - A.issubset(B) is False; shorthand: A <= B
- A.issuperset(B) is False; shorthand: A >= B
{1,2,3} == {1,3,2}
set.add()
set.remove()