3.9 Dictionaries
I went into detail about lists to illustrate the main collection operations you need to know:
- Creating a collection
- Testing for membership in a collection
- Accessing items in a collection
- Adding items to a collection, if it is mutable
- Removing items from a collection, if it is mutable
- Iterating over items in the collection
- Extracting a sub-collection
- Building a new collection by calling functions on items filtered from an existing collection
For dictionaries and sets, I move faster over these core operations and focus on the distinguishing features of the collection types.
3.9.1 What is a dictionary?
Let’s begin by putting our information about guitars into the table in Figure 3.6.
A Python dictionary...