Question: PYTHON ONLY! ONLY USE IMPORTS GIVING NOT YOUR OWN! PLEASE FOLLOW DIRECTIONS PLEASE!! Implement the function count_word_frequencies () in word_frequencies.py that takes a list of
PYTHON ONLY! ONLY USE IMPORTS GIVING NOT YOUR OWN! PLEASE FOLLOW DIRECTIONS PLEASE!!
Implement the function count_word_frequencies () in word_frequencies.py that takes a list of words as argument and returns a dictionary whose keys are the words from the list and values are the corresponding frequencies. Also implement the function write-word frequencies () that takes a dictionary as argument and writes (in reverse order of values) the key-value pairs of the dictionary to standard output, one per line, and with a between a ' rightarrow ' between a key and the corresponding value. $ python word_frequencies.py it was the best of times it was the worst of times of rightarrow 2 it rightarrow 2 times rightarrow 2 the rightarrow 2 Was rightarrow 2 worst rightarrow 1 best rightarrow 1 import operator import stdio import sys # Returns a list containing the keys of the dictionary st in reverse order # of the values of the dictionary. def keys (st): a sorted (st. items(), key = operator.itemgetter (1), reverse = True) return [v[0] for v in a] # Returns a dictionary whose keys are the words from the given list of words # and values are the corresponding frequencies. def count_word_frequencies (words): ellipsis # Writes (in reverse order of values) the key-value pairs of the dictionary # st to standard output, one per line, and with a ' rightarrow ' between a key and # the corresponding value. def write_word_frequencies (st): ellipsis # Test client [DO NOT EDIT]. Reads words from standard input and writes # the words along with their frequencies, in reverse order of frequencies. def_main(): words = stdio.readAllStrings () write_word_frequencies (Count_word_frequencies (words)) if _name_ == ' _main_ ': _main ()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
