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