Sets & Dictionaries
Containers that answer “is this in here?” and “what goes with this key?” in constant time, by jumping straight to where the answer lives.
After this lesson you will be able to
- Explain what a set and a dictionary store, and when each is the right container.
- Describe, in plain terms, how a hash table finds an item without searching, and what a collision is.
- Use set operations (union, intersection, difference) and dictionary methods (
get,items, counting, grouping). - Count items with a dictionary,
Counterordefaultdict. - State the cost of the operations (average O(1)) and the rules about hashable keys.
Before you start. Python Basics. Lists & Tuples help, because tuples are the usual compound keys.