Any running Python program has many dictionaries active at the same time, even if the user’s program code doesn’t explicitly use a dictionary.
— A. M. Kuchling Chapter 18, “Python’s Dictionary Implementation
dict type is not only widely used in our programs but also a fundamental part of the Python implementation. Module namespaces, class and instance attributes, and function keyword arguments are some of the fundamental constructs where dictionaries are deployed. The built-in functions live in
Because of their crucial role, Python dicts are highly optimized. Hash tables are the engines behind Python’s high-performance dicts.
We also cover sets in this chapter because they are implemented with hash tables as well. Knowing how a hash table works is key to making the most of dictionaries and sets.
Here is a brief outline of this chapter:
dictin the standard library
collections.abc module provides the
MutableMapping ABCs to formalize the interfaces of
dict and similar types (in Python 2.6 to 3.2, these classes are imported from the
collections module, and not from
collections.abc). See Figure 3-1.