Question: Write a function, print_histogram(a_dict), which takes a Python dictionary as a parameter. The keys of the dictionary are single letters and the corresponding values are

Write a function, print_histogram(a_dict), which takes a Python dictionary as a parameter. The keys of the dictionary are single letters and the corresponding values are integers, e.g., {'b': 5, 'a': 6, 'c': 3}. The function should print a histogram shown as below. Note: the keys are printed in alphabetical order and the number of stars printed is given by the value corresponding to the key. If the parameter dictionary is empty, the function prints nothing.

For example:

print_histogram({'c':3, 'a':6, 'b':5})

Results:

a : ****** b : ***** c : ***

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!