Dictionaries Dictionaries: Congratulations! You Passed!
Dictionaries Dictionaries: Congratulations! You Passed!
Introduction
Congratulations! You passed! GRADE
Quiz: Dictionaries
7 questions
Dictionaries
LATEST SUBMISSION GRADE
100%
Receive grade {}
TO PASS 70% or higher
Correct
dict()
Correct
<>
()
2. Given an existing dictionary favorites, what Python statement adds the key "fruit" to this 1 / 1 point
dictionary with the corresponding value "blackberry"?
favorites["fruit" = "blackberry"]
favorites{"fruit" : "blackberry"}
favorites["fruit"] = "blackberry"
favorites["fruit" : "blackberry"]
Correct
3. Which of the expressions below returns True when the dictionary my_dictionary contains the key 1 / 1 point
my_key and False otherwise?
my_key in my_dictionary
Correct
my_dictionary.has_key(my_key)
my_dictionary.key(my_key)
my_dictionary[my_key]
list
bool
Correct
dict
int
Correct
string
Correct
dict
Correct
tuple
Correct
bool
Correct
Since "John" is not a key in the dictionary, Python raises a KeyError exception.
Python returns the value None since "John" is not a key in the dictionary.
Since "John" is not a value in the dictionary, Python raises a KeyError exception.
Since "John" is not a key in the dictionary, Python raises a syntax error.
Correct
7. Write a function count_letters(word_list) that takes as input a list of words that are 1 / 1 point
composed entirely of lower case letters . This function should return the lower case letter that
appears most frequently (total number of occurrences) in the words in word_list. (In the case of
ties, return the earliest letter in alphabetical order.)
The Python code snippet below represents a start at implementing count_letters using a
dictionary letter_count whose keys are the lower case letters and whose values are the
corresponding number of occurrences of each letter in the strings in word_list.
1 def count_letters(word_list):
2 """ See question description """
3
4 ALPHABET = "abcdefghijklmnopqrstuvwxyz"
5
6 letter_count = {}
7 for letter in ALPHABET:
8 letter_count[letter] = 0
9
10 # enter code here
When you are con dent in your code, compute the lower case letter return by
count_letters(monty_words) where monty_words is de ned as shown.
Enter this single letter in the text box below. Do not include any spaces or enclosing quotes around
the letter.
Correct