Dictionaries, Sets & Hashing Contracts

Unit 3: Built-in Data Structures & Hashing · 8 min read

Why dict and set lookups average O(1), what makes an object hashable, insertion-order guarantees, and Counter/defaultdict patterns.

Key Concepts

  • Hashability requires stable __hash__ and __eq__
  • Safe lookups with dict.get(), setdefault(), and defaultdict
  • Insertion order preservation since Python 3.7+
  • Replacing nested O(n^2) loops with hash maps/sets

Official Python Docs

Back to Python Notes Hub