questions
90 2 Run CH Markdown L05: Dictionaries, hashmaps Q1- Making a Dictionary (25 points) Create a dictionary of student heights where each student's name (Capitalized) is the key, and their height, (in feet, float) is the value. Call this dictionary results dictionary. In [ 11 # YOUR CODE HERE raise NotImplementedError() In []: from math import isclose assert isinstance(results_dictionary, dict) Show Usage Validate assert isclose(results_dictionary['Vanessa'], 5.2) assert isclose(results_dictionary['sarah'], 5.4) assert isclose(results dictionary['Demi'], 6.1) assert isclose(results_dictionary['George'], 5.6) assert isclose(results_dictionary['Dawn'], 5.9) name height Vanessa 52 Sarah 54 Demi 61 George Dawn 59
Q2-Counting things with dictionaries. (25 points) Build a dictionary called word_count that represents the number of times each word occurred in the list called word list via a for loop. Note that some of the items in word_list are not words! In [ ]: word_list = ['whose", "woods', 'these', 'are', 'i', 'think', "i", "know", "his", "house', 'is', 'in', 'the', 'village', 'though In [ ]: word_count = dict(). #YOUR CODE HERE raise NotImplementedError() In 1: assert len(word_count) == 74 assert word_count ['woods'] == 4 assert word count['his'] == 3 assert sum(word_count.values()) == 108
Build a dictionary called word count that represents the number of times each word occurred in the list called word list via a for loop. Note that some of the items in word list are not words! In he', 'will', 'not', 'see', stopping', 'here', 'to', 'watch', 'his', 'woods", fill', 'up', 'with', 'snow', '11
Build a dictionary called word count that represents the number of times each word occurred in the list called word list via a for loop. Note that some of the items in word list are not words! In little', 'horse', must', 'think', 'it', 'queer', 'to', 'stop', 'without', 'a', 'farmhouse', 'near', 'between', 'the', 'woods"
Build a dictionary called word count that represents the number of times each word occurred in the list called word list via a for loop. Note that some of the items in word_list are not words! In [ ]: 'and', 'frozen', 'lake", "the', 'darkest', 'evening', 'of', 'the', 'year', , 'he, gives", "his', 'harness', 'bells', 'a',
Build a dictionary called word_count that represents the number of times each word occurred in the list called word list via a for loop. Note that some of the items in word list are not words! In 1: shake', 'to', 'ask', 'if', 'there', "'is' 'mistake', 'the', 'only', 'other', 'sounds', 'the', 'sweep', 'of', "easy", "wit
Build a dictionary called word count that represents the number of times each word occurred in the list called word list via a for loop. Note that some of the items in word list are not words! in : wind, and', 'downy', 'flake"," "the", "woods", "are", "lovely', 'dark", "and', 'deep', 'but', '1', have, promises, to
enot words! each word occurred in the list called word_list via a for loop. Note that some of eep', 'and', 'miles', 'to', 'go', 'before', '1', 'sleep', 'and', 'miles', 'to', 'go', 'before', 'i', 'sleep']
Q3 - Dictionaries as lookups (25 points) Roman numerals are a funny mapping between letters and numbers. For the most part, each letter has a value, and you add those values up. For instance, T=1, V=5, and V = 5+1 = 6. However, there are particular two-letter symbols that have a meaning that is not the sum of the two letters, for instance: TV means 5-1 or 4. Below we provide a list of all the one-character values (one_char), and all the special two-character values (two_char). And a list of symbols (correctly grouped into 1 or 2 letter combinations). Make a new list called values where each element of that list corresponds to the symbol value of the corresponding element in the symbols list. In other words, if a given symbol is in the two char dictionary, then that should be its value. If it is in the one char dictionary, then that should be the value. If it is in neither dictionary then None should be the value. In [ ]: two_char = ('IV' :4, IX'19, XL:40, xc':90, 'CD':400, 'CM':900) one_char = ('1':1, 'V':5, 'X':10, 'L':50, 'c':100, '0'1500, 'M':1000) symbols = ['IV', 'H', 'G', 'L', '0', 'CM', 'IX', 'M', 'CD', 'M', 'XC', 'M', 'M', 'IX', 'AB', #YOUR CODE HERE raise NotImplementedError() In 1: assert isinstance(values, list) len(symbols) assert len(values) assert values[0] == 4 assert values[-2] assert values[2] == None 500 'V', '0', 'xc']
Q4 - most common words (25 points) In Q2 you made a dictionary of word counts (called word_count). Here, please find the most common word in that dictionary, and store it in the variable called most common. Do not hard-code the answert Your code should get the correct answer even if the contents of word_count were different. In 1: YOUR CODE HERE raise NotimplementedError() In 1: assert most commons "the"
all 90 2 Run CH Markdown L05: Dictionaries, hashmaps Q1- Making a Dictionary (25 points) Create a dictionary of student heig
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am