logo CodeStepByStep logo

least_common

Language/Type: Python dict collections

Write a function least_common that accepts a dictionary whose keys are strings and whose values are integers as a parameter and returns the integer value that occurs the fewest times in the dictionary. For example, if a dictionary named m contains {'Alyssa': 22, 'Char': 25, 'Dan': 25, 'Jeff': 20, 'Kasey': 20, 'Kim': 20, 'Mogran': 25, 'Ryan': 25, 'Stef': 22}, the call of least_common(m) returns 22. If there is a tie, return the smaller integer value. If the map is empty, throw a ValueError.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.