Page 1 of 1

The following code calculates the max value and the corresponding key in a frequency dictionary. freq {'C': 43, 'F': 12,

Posted: Tue Jul 12, 2022 8:21 am
by answerhappygod
The Following Code Calculates The Max Value And The Corresponding Key In A Frequency Dictionary Freq C 43 F 12 1
The Following Code Calculates The Max Value And The Corresponding Key In A Frequency Dictionary Freq C 43 F 12 1 (61.68 KiB) Viewed 18 times
The following code calculates the max value and the corresponding key in a frequency dictionary. freq {'C': 43, 'F': 12, 'B':24, 'A': 9, 'G': 23, 'E': 65, 'D': 2, 'H': 43, 'I': 12, 'K':2, 'L': 7} maxValue, maxKey = 0, 0 for k in freq: if freq[k]> maxValue: maxValue = freq[k] maxkey = k print("The key {0} corresponds to the max value of {1}.".format(maxKey, maxValue)) The key E corresponds to the max value of 65. Create a function maxValKey that does exactly the same with the following requirements: • the dictionary is passed as the argument "arg1" • the function returns two values, maxValue and maxkey freq = {'C': 43, 'F': 12, 'B':24, 'A': 9, 'G': 23, 'E': 65, 'D': 2, 'H': 43, 'I': 12, 'K':2, 'L': 7} Wr your function def maxValkey (arg1): # write the code here return ?,? # replace question marks with your variable' names File "<ipython-input-8-0c3b473d0a26>", line 5 return ?,? # replace question marks with your variable' names ^ SyntaxError: invalid syntax Try the function. The expected outcome is: • "The key E corresponds to the max value of 65." # try your code here a, b = maxValKey (freq) print("The key {0} corresponds to the max value of {1}.".format(a, b))