Codele / Data structures
Sets
A set is a bag where each thing can appear only once, like a stamp album. Adding a repeat does nothing, and “do I have it?” is answered at once.
- A set keeps each thing only once. Adding something that is already there changes nothing.
- “Is it in there?” is answered at once, because a set finds things the way a dictionary finds keys.
- A set has no order and no positions. Do not rely on which item comes out first.
- Turning a list into a set is the quickest way to remove repeats and count the different things.
- The intersection of two sets is what they share. Go has no set type, so it uses a dictionary whose values are true.
Loading the playable lesson…