🔥 BLACK FRIDAY SALE1 course ₹199·any 3 courses ₹399 for 3 months·ALL courses + 1 mock interview ₹599 for 6 monthsClaim offer →

Python · Python Foundations · Foundation · 26 min read

Python Dictionaries, Sets and Hashing: How Hash Tables Work and Choosing the Right Mapping

Master Python's fastest data structures. Learn how hash tables work, hashability and the hash/eq contract, dictionary API and patterns (get, setdefault, defaultdict, Counter, merging), insertion order, views, set operations, frozenset, performance and collisions, common bugs with mutable keys and iteration, and choosing between dict, set, Counter, ChainMap and friends.

Python Dictionaries, Sets and Hashing: How Hash Tables Work and Choosing the Right Mapping: lesson illustration

A first look

  • Foundation level · 26 min read
  • 7 interview questions with model answers
  • Python Foundations · Python Mastery

You will learn to

  • How a hash table gives O(1) lookup, and why keys must be hashable
  • The hash and eq contract
  • Dictionary API and idioms, ordering guarantees and views
  • …and 4 more topics inside
Create an account to start

Create a free account to see what this lesson covers

  • Every free lesson in every section, in full
  • Track your progress and pick up where you left off
  • Free practice questions and an incident simulation
  • Takes under a minute: name, email and a password

No card needed. Full access to Python is a paid upgrade you can choose later.