Build up a good understanding for sets as a data structure and find use cases where it shines.
Set
Definition: Unordered, mutable, no duplicates.
Syntax: my_set = {1, 2, 3}
Common operations & properties:
- Add:
my_set.add(4)
- Remove:
my_set.remove(2)
- Union:
set1 | set2
- Intersection:
set1 & set2
- Difference:
set1 - set2
- Membership:
3 in my_set
Build up a good understanding for sets as a data structure and find use cases where it shines.
Set
Definition: Unordered, mutable, no duplicates.
Syntax:
my_set = {1, 2, 3}Common operations & properties:
my_set.add(4)my_set.remove(2)set1 | set2set1 & set2set1 - set23 in my_set