Python Reading
- Read the chapter entitled Dictionaries
from section "Dictionaries" through section "Dictionary Operations"
Key Ideas
- A dictionary is an unordered collection of key-value pairs.
- Creating an empty dictionary: homeruns = {}
- Adding a key-value pair: homeruns["Babe Ruth"] = 713 (note: he hit 714)
- Adding another pair: homeruns["Mickey Mantle"] = 536
- Deleting an item: del homeruns["Mickey Mantle"]
- Modifying an item: homeruns["Babe Ruth"] = 714
- Determining the number of items in a dictionary: len(homeruns)
In-Class Activity
- Download and experiment with raven.py and
raven.txt until you understand
how raven.py works.
Active Learning
- Modify raven.py to count and print the occurrences of each
letter in the alphabet from 'a' to 'z', regardless of whether it
is lowercase or uppercase. Use a dictionary in your solution.