should return 5, since character s does not occur in the input string. • most_frequent( n=1 ) should return the most frequently occurring elements in the given sequence. If n= , then the most frequent...


should return 5, since character s does not occur in the input string.<br>• most_frequent( n=1 ) should return the most frequently occurring elements in the given sequence. If n= , then the most frequent should be returned<br>in a tuple along with its frequency value. For example,<br>h.most_frequent()<br>should return ('a', 3)<br>If n is larger than 1, then the function should return an ordered list of tuples of the top n most frequent values. For example,<br>h.most_frequent( n=2 )<br>should return [('a', 3), ('b', 2)].<br>If n is larger than the number of elements, then this method should return all elements and their corresponding values. For example,<br>h.most_frequent( 100 )<br>should return [('a', 3), ('b', 2), ('c', 1)].<br>• values () should return the values in the histogram in a list. The order of the returned values is immaterial. See test cases below.<br>• elements () should return the elements in the histogram, akin to the keys in a dictionary. See test cases below.<br>• items () should return a list of two-tuples, in which the first item is the element and second item is the frequency value. See test cases below.<br>• remove( element ) should remove the indicated element from the histogram and returns the frequency value for that element. If that element is not<br>present in the histogram, this instance method should raise a KeyError. See test cases below.<br>

Extracted text: should return 5, since character s does not occur in the input string. • most_frequent( n=1 ) should return the most frequently occurring elements in the given sequence. If n= , then the most frequent should be returned in a tuple along with its frequency value. For example, h.most_frequent() should return ('a', 3) If n is larger than 1, then the function should return an ordered list of tuples of the top n most frequent values. For example, h.most_frequent( n=2 ) should return [('a', 3), ('b', 2)]. If n is larger than the number of elements, then this method should return all elements and their corresponding values. For example, h.most_frequent( 100 ) should return [('a', 3), ('b', 2), ('c', 1)]. • values () should return the values in the histogram in a list. The order of the returned values is immaterial. See test cases below. • elements () should return the elements in the histogram, akin to the keys in a dictionary. See test cases below. • items () should return a list of two-tuples, in which the first item is the element and second item is the frequency value. See test cases below. • remove( element ) should remove the indicated element from the histogram and returns the frequency value for that element. If that element is not present in the histogram, this instance method should raise a KeyError. See test cases below.
Question 1<br>Write a Python class named Histogram that keeps track of how many times each unique element in a given sequence occurs. This class will implement the<br>following interface:<br>• Histogram( sequence ) will create a histogram of all elements occurring in the given sequence.<br>This class cannot use the dict or collections.Counter types to create instance or class variables in order to implement the following<br>specifications! If it does, the grade for your solution will automatically be zero! However, in some cases, your code will have to return dictionaries. So note<br>the difference between the two specifications!<br>• get( element-None, default-e ) will return how many times<br>given element occurs in the histogram. If no element is specified, then the get ()<br>function will retum a dictionary where keys are elements and values are number of times a given element occurs in the sequence provided to the<br>initializer. For example, given<br>h - Histogram(

Extracted text: Question 1 Write a Python class named Histogram that keeps track of how many times each unique element in a given sequence occurs. This class will implement the following interface: • Histogram( sequence ) will create a histogram of all elements occurring in the given sequence. This class cannot use the dict or collections.Counter types to create instance or class variables in order to implement the following specifications! If it does, the grade for your solution will automatically be zero! However, in some cases, your code will have to return dictionaries. So note the difference between the two specifications! • get( element-None, default-e ) will return how many times given element occurs in the histogram. If no element is specified, then the get () function will retum a dictionary where keys are elements and values are number of times a given element occurs in the sequence provided to the initializer. For example, given h - Histogram( "aaabbc" ) then h.get( "b" ) should return 2, and h.get() should return {"a": 3, "b": 2, "c": 1}. If the provided character does not occur in the input string, then get () should return the value provided as default in the default argument. If not provided, get() should returm e for a non-occurring character. For example, h. get( "s", 5) should return 5, since character s does not occur in the input string. • most_frequent( n-1 ) should retum the most frequently occurring elements in the given sequence. If n-, then the most frequent should be returned in a tuple along with its frequency value, For example.
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here