Dictionaries

A dictionary is a fancy list
  • A dictionary consists of (key,value) pairs

  • The key is an immutable type(e.g. a number, a string, a tuple)

  • The value can be anything

  • We retrieve the value in a dictionary by using the associated key

  • Dictionaries are fancy lists that are not restricted to consecutive integers for indexing

  • We create dictionaries with curly braces { }

  • We assign elements to and retrieve elements from dictionaries with square brackets [key]

  • Dictionaries can be constructed from a list of (key,value) pairs (or 2-turples)from two matching lists or keys and values

Last updated

Was this helpful?