Python Tutorial · Revision notes

Python Dictionaries

A dictionary maps unique keys to values. This chapter covers creating and updating dictionaries, the main dictionary methods, and clear comparisons with list, set and tuple.

Quick revision

  • Dict: key to value, unique hashable keys, ordered (3.7+)
  • d[k] raises KeyError; d.get(k, default) does not
  • in checks keys
  • update, pop, popitem, setdefault, items
  • List by index, dict by key
  • List [] / tuple () / set {} unique / dict {k: v}
Read the full Python Dictionaries notes on Doubtclip →