15-110 Lecture Topics:  Dictionaries

Week #8  Oct 11 – Oct 15

  1. What is a dictionary?
    1.  It is a map from keys to values
    2.  Adding, removing, getting, and setting are all fast (eg, much faster than using a sorted list of tuples)
    3.  Keys are a set:  they are unique and unsorted
  2. How to...
    1.  Create a dictionary
      1.  Create an empty dictionary
      2. Create a dictionary from a list of tuples
    2.  Add a key/value
    3. Delete a key
    4.  Get a value from a key
    5.  Modify a key/value
    6. Get all keys
  3. Usage
    1. Can use mixed types for keys and values
    2. Keys are case-sensitive
    3. Don't use a dictionary like a list
  4. Recommended Reading
    1. http://docs.python.org/library/stdtypes.html#typesmapping
    2. http://docs.python.org/tutorial/datastructures.html
    3. http://diveintopython.org/getting_to_know_python/dictionaries.html