Python Data Analysis Week1

docx

School

Grand Rapids Community College *

*We aren’t endorsed by this school

Course

247

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

3

Uploaded by ConstableWildcatMaster401

Report
Congratulations! You passed! Grade received 71.42% Latest Submission Grade 71.43% To pass 70% or higher Go to next item 1. Question 1 Which of the following expressions corresponds to a dictionary with no elements? 1 / 1 point dict() dict() Correct <> <> {} {} Correct () () 2. Question 2 Given an existing dictionary favorites favorites , what Python statement adds the key "fruit" "fruit" to this dictionary with the corresponding value "blackberry" "blackberry" ? 1 / 1 point favorites = {"fruit" : "blackberry"} favorites = {"fruit" : "blackberry"} favorites{"fruit" : "blackberry"} favorites{"fruit" : "blackberry"} favorites["fruit" : "blackberry"] favorites["fruit" : "blackberry"] favorites["fruit"] = "blackberry" favorites["fruit"] = "blackberry" favorites["fruit" = "blackberry"] favorites["fruit" = "blackberry"] Correct 3. Question 3 Which of the expressions below returns True True when the dictionary my_dictionary my_dictionary contains the key my_key my_key and False False otherwise? 1 / 1 point my_dictionary.has_key(my_key) my_dictionary.has_key(my_key) my_key in my_dictionary my_key in my_dictionary Correct my_dictionary.my_key() my_dictionary.my_key() my_dictionary contains my_key my_dictionary contains my_key 4. Question 4 Keys in a dictionary can have which of the following types? 1 / 1 point dict list bool Correct Booleans are immutable. int Correct Integers are immutable.
5. Question 5 Values in a dictionary can have which of the following types? 0 / 1 point dict tuple Correct string Correct bool Correct You didn’t select all the correct answers 6. Question 6 Consider the following dictionary: 1 instructor_ratings = { "Joe" : "awesome" , "Scott" : "hmmm..." } What happens when Python evaluates the expression instructor_ratings["John"] instructor_ratings["John"] ? 0 / 1 point Since "John" "John" is not a key in the dictionary, Python raises a syntax error. Since "John" "John" is not a key in the dictionary, Python raises a KeyError exception. Python returns the value None None since "John" "John" is not a key in the dictionary. Since "John" "John" is not a value in the dictionary, Python raises a KeyError exception. Incorrect Note that "John" "John" is a key in the dictionary, not a value. 7. Question 7 Write a function count_letters(word_list) count_letters(word_list) that takes as input a list of words that are 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 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 count_letters using a dictionary letter_count 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 word_list . 1 2 3 4 5 6 7 8 9
10 def count_letters(word_list): """ See question description """ ALPHABET = "abcdefghijklmnopqrstuvwxyz" letter_count = {} for letter in ALPHABET: letter_count[letter] = 0 # enter code here Complete your implementation of count_letters count_letters based on this snippet. As a test, count_letters(["hello", "world"]) count_letters(["hello", "world"]) should return the letter 'l' ’l’ since 'l' ’l’ appears 3 times total in the strings "hello" "hello" and "world" "world" . When you are confident in your code, compute the lower case letter return by count_letters(monty_words) count_letters(monty_words) where monty_words monty_words is defined as shown. 1 2 3 monty_quote = "listen strange women lying in ponds distributing swords is no basis for a system of go vernment supreme executive power derives from a mandate from the masses not from some farcical a quatic ceremony" monty_words = monty_quote.split( " " ) Enter this single letter in the text box below. Do not include any spaces or enclosing quotes around the letter. 1 / 1 point e Correct The letter 'e' ’e’ appears 20 times in the quote.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help