Question: (Python): Can reuse this function below def make_hist(string): returns histogram from the 'string' str -> histogram hist = {} for i in range(len(string)): for element
(Python): Can reuse this function below
def make_hist(string): """returns histogram from the 'string'
str -> histogram""" hist = {} for i in range(len(string)): for element in string: hist[element] = string.count(element) return hist
a)
Define a function histoprint1() that takes a dictionary representing a histogram (keeps track of how many times each value occurs in a set of data), and prints out a "graphical" representation of the histogram, one entry per output line. Each printed line should represent a (key, value) pair in the dictionary: starting with the dictionary key (a single character string), followed by a : and as many #s as the dictionary value. Use the output from Python print() statements to build graphical representations of histograms. For example,histoprint1(make_hist("Mississippi")) should look something like this:
i: #### M: # p: ## s: ####
b)
Define a function histoprint2() that takes a dictionary representing a histogram, and prints out a sortedgraphical representation of the histogram, one entry per output line (unlikehistoprint1(), the function histoprint2() should always produce the same output). The entries should be sorted alphabetically by the keys. For example, histoprint2(make_hist("bicycling")) should look something like this:
b: # c: ## g: # i: ## l: # n: # y: #
c)
Define a function histoprint3() that takes a dictionary representing a histogram and an integer representing a scaling factor. It should print out a sorted graphical representation of the histogram, one entry per output line, where each hash mark # stands in for several occurrences of the character (how many is specified by the scaling factor). If the scaling factor is left out, then it should use 1 as a default.
So for example, histoprint3((make_hist("A man, a plan, a canal: panama.")),1)* would display the histogram with each hash mark representing one occurrence:
: ###### ,: ## .: # :: # A: # a: ######### c: # l: ## m: ## n: #### p: ##
But histoprint3((make_hist("A man, a plan, a canal: panama.")),2) would display the histogram with each hash mark representing two occurrences:
: ### ,: # .: :: A: a: #### c: l: # m: # n: ## p: #
Some of the entries look blank because the scale is so big that the frequencies of those infrequent characters are less than a hash mark.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
