Question: frequency(d) Given a dictionary d, where it is guaranteed that keys are strings and values are integers, return the value in d with the highest

frequency(d) Given a dictionary d, where it is guaranteed that keys are strings and values are integers, return the value in d with the highest occurrence. If more than one value occurs the most, return the value that appeared first in d.

You are NOT allowed to use count(), max(), min() or any other Python count libraries such as Counter and mode (No credit will be given to your code if you use them) Preconditions d: non-empty dictionary Returns: int -> value that occurs the most times in d

Example:

>>> frequency({'a':2, 'b':2, 'c':1, 'd':1, 'e':5, 'f':1}) 1

>>> frequency({'a':2, 'b':2, 'c':1, 'd':1}) 2

>>> frequency({'a':2, 'b':2, 'c':1, 'd':1, 'h':2, 't':6, 'rr':6, 'rws':6}) 2

>>> answer = frequency({'a':2, 'b':2, 'c':1, 'd':1, 'h':2, 't':6, 'rr':6, 'w':6, 'e':6, 'z':5})

>>> answer

>>>6

def frequency(d):
# - YOUR CODE STARTS HERE -

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!