Question
In the module of dictionary, we learned to write the histogram function to count how many times each letter appears in a given string. Here's
In the module of dictionary, we learned to write the histogram function to count how many times each letter appears in a given string. Here's the histogram function:
def histogram(s): d = dict() for c in s: if c not in d: d[c]=1 else: d[c]+=1 return d
We also learned about the get function of dictionary.
Use get to write a function called ordered_histogram. You should be able to eliminate the if statement. The function should return a dictionary type at the end, which contains keys and their values in alphabetical order.
Submit the screen capture of the running program and it's output, and submit the python code in .py format.
Dictionaries are ordered in Python 3.6 (under the CPython implementation) unlike in previous incarnations. So when you construct the dictionary, your need to insert key/value pairs in the order you want.
Using OrderedDict is not required, NOT REQUIRED.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started