Python Dictionaries
Objective 3.3 covers dictionaries: a mapping from keys to values, where the keys must be hashable and the values need not be. Two facts in circulation are out of date - dictionaries have kept insertion order since Python 3.7, and has_key() has not existed since Python 2. The rest is a small method list plus one genuinely surprising result about which keys count as the same key.
Data Collections Guide 16 of 26 Beginner
- OSUbuntu 26.04 LTS
- Python3.14.4
- pip25.1.1
- TimeAbout 17 min
Insertion order has been guaranteed since Python 3.7 and was already true as an implementation detail in 3.6. Any material describing dictionaries as unordered, or using d.has_key(k), is Python 2 or pre-3.7 and should be distrusted generally - see guide 3.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Python 3.14.4 - the only machine this path needs | 2 Core | 4 GB | 50 GB |
This guide includes
Use this for the dictionary objective. This matters because a missing key raises where the method for the same job does not - and in tests keys and never values, which is what this objective asks most.
- performing the four operations on a mapping
- finding what a missing key raises, and what
inactually tests - using the three views, over keys, values and items
- learning what counts as the same key, and what order a dictionary keeps
- using the methods that change one, and the other ways to build one
Before you start
- guide 15 - keys must be hashable, and that is why.
- guide 11 - iterating a dictionary gives its keys.
-
The four operations
-
A key that is not there
-
The three views
-
Order, and what counts as the same key
-
The methods that change a dictionary
-
Other ways to build one
-
What the exam does with this objective