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.


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

41 out of 48 users completed this Bite.
Will you be Pythonista #42 to crack this Bite?
Resolution time: ~74 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.
We use Python 3.8