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

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

We use Python 3.8