Affiliate disclosure

Book titles on this page link to Amazon. As an Amazon Associate, DataField.Dev earns from qualifying purchases — at no additional cost to you.

Further Reading: Dictionaries and Sets

Python Documentation

  • Python Tutorial: Data Structures (Dictionaries section). (Tier 1) The official Python tutorial covers dict operations concisely. Start here for a quick, authoritative tour; the "Mapping Types — dict" section of the Library Reference (docs.python.org/3/library/stdtypes.html) is the full reference for methods like .get(), .items(), .update(), and .pop(). Available at docs.python.org/3/tutorial/datastructures.html#dictionaries.

  • Python Documentation: collections module. (Tier 1) The official docs for defaultdict, Counter, OrderedDict, and ChainMap. The Counter class in particular has many useful methods beyond .most_common() that are worth exploring. Available at docs.python.org/3/library/collections.html.

Understanding Hash Tables

  • Downey, A. Think Python, 3rd Edition, Chapter 10: Dictionaries. (Tier 1) A complementary, beginner-friendly treatment of dictionaries. Section 10.3 explains that dicts are stored in a hash table and times a list-based search against a dict-based one on a word list of over 100,000 words (the dict version is about 10,000 times faster), and Section 10.6 explains why keys have to be hashable. Free online at allendowney.github.io/ThinkPython.

  • Rhodes, B. "The Mighty Dictionary" (Talk, PyCon 2010). (Tier 2) A clear, picture-driven explanation of how Python's dictionary works under the hood: hashing, slots, and collisions. If you want to understand why dictionary lookup is O(1) on average, this talk is a good starting point. His PyCon 2017 follow-up, "The Dictionary Even Mightier," covers the changes up to Python 3.6.

  • Cormen, T. et al. Introduction to Algorithms, 4th Edition, Chapter 11: Hash Tables. (Tier 1) The definitive academic treatment of hash tables, hash functions, and collision resolution. Significantly more advanced than what's needed for this course, but excellent if you're curious about the theory.

Practical Applications

  • Sweigart, A. Automate the Boring Stuff with Python, 3rd Edition, Chapter 7: Dictionaries and Structuring Data. (Tier 1) Practical dictionary examples focused on real-world tasks: modeling a chessboard, nested dictionaries and lists, and a fantasy game inventory practice program. Free online at automatetheboringstuff.com. (In the 2nd edition, the same material is Chapter 5.)

  • Lutz, M. Learning Python, 6th Edition, Chapter 8: Lists and Dictionaries. (Tier 1) A thorough reference covering dictionary methods, iteration, and comparison with lists. More detailed than most introductory treatments.

JSON and Web Data

  • json.org: Introducing JSON. (Tier 1) The specification for JSON (JavaScript Object Notation). Compare the JSON data types with Python's — the mapping is almost one-to-one. This will prepare you for Chapter 10's file I/O content.

  • Mozilla Developer Network: Working with JSON. (Tier 2) While aimed at JavaScript developers, this MDN guide provides clear explanations of JSON structure that map directly to Python dicts. Available at developer.mozilla.org.

Sets and Mathematical Foundations

  • Rosen, K. Discrete Mathematics and Its Applications, Chapter 2: Basic Structures: Sets, Functions, Sequences, Sums, and Matrices. (Tier 1) If you want to understand the mathematical foundations of set operations, Sections 2.1 and 2.2 give rigorous definitions of sets, power sets, union, intersection, difference, and complement.

Performance and Big-O

  • Python Wiki: "TimeComplexity." (Tier 2) A community-maintained table of the average and worst-case cost of common operations on CPython's lists, dicts, sets, and deques. It shows at a glance why x in some_set is O(1) on average while x in some_list is O(n). Available at wiki.python.org/moin/TimeComplexity.

For the Curious

  • Hettinger, R. "Modern Python Dictionaries: A Confluence of a Dozen Great Ideas" (Talk, PyCon 2017). (Tier 1) Raymond Hettinger, a Python core developer who first proposed the compact dict layout (in 2012), explains how CPython's dictionary implementation was redesigned in Python 3.6 to use 20–25% less memory while preserving insertion order (which became a language guarantee in Python 3.7). Technical but accessible if you enjoy understanding how things work under the hood.

  • Ramalho, L. Fluent Python, 2nd Edition, Chapter 3: Dictionaries and Sets. (Tier 1) An advanced treatment covering __hash__, __eq__, dict internals, set theory in Python, and MappingProxyType. Best read after completing this course, but an excellent next step.