Download and save ACT2-5.py
. Open it in IDLE
and press F5. Three variables are already defined: origString
, freqDict
, and phoneDict
.
freqDict
.
phoneDict
.
'a'
in the freqDict
dictionary is freqDict['a']
. Try this in a Python shell.'hat'
and 'the'
in the freqDict
dictionary.'Carol'
and 'Doug'
in the phoneDict
dictionary.key in dict
syntax to determine if the string 'mat'
is a key in freqDict
.in
syntax to determine if the string 'Alice'
is in phoneDict
.keys()
function to get a list of keys for freqDict
and then for phoneDict
.values()
function to get a list of keys for freqDict
and then for phoneDict
.keys()
or values()
) would make this task easier? Why? How would you accomplish this task with the other function (you don't have to write code, just think about it)?'mat'
with the value 0
to freqDict
. Verify your change by evaluating freqDict
.'cat'
from freqDict
. Verify your change by evaluating freqDict
.'Alice'
with the value '401-555-5555'
in phoneDict
. What happened to the dictionary? What does this mean about keys?printDict()
function. How does it print the key-value pairs for a dictionary? Run printDict()
on freqDict
and then phoneDict
.printList()
function. Since this function takes a list, use the split()
function to split origString
on whitespace. Pass this list to the printList()
function. What differences and similarities do you notice when you compare the output of printDict()
and printList()
?wordFreq()
function. Fill in the function so that it actually returns a dictionary of word frequencies instead of always an empty dictionary.