avatar Bite 308. Calculate the median from a dictionary

You are in charge of a program that continuously collects measurements. On demand, it outputs the median of the collected numbers.

In order to save memory, the numbers are not saved in a list but in a dictionary containing the counts of each number, similar to collections.Counter.

Write a function that calculates the median from the supplied dictionary.

Example:

>>> d = {1: 3, 2: 1, 4: 3}
# 1, 1, 1, 2, 4, 4, 4
>>> calc_median_from_dict(d)
2
Login and get coding
go back Intermediate level
Bitecoin 3X

46 out of 58 users completed this Bite.
Will you be Pythonista #47 to crack this Bite?
Resolution time: ~78 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 7.0 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help