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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 16 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))
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply