Question: In python and please post a screenshot of file input (your code) next to the python shell (output) DICT HASH TABLE Given a number n,

In python and please post a screenshot of file input (your code) next to the python shell (output)

DICT HASH TABLE

Given a number n, followed by n lines of text, print all words encountered in the text, one per line. The words should be sorted in descending order according to their number of occurrences in the text, and all words with the same frequency should be printed in lexicographical order.

Hint. After you create a dictionary of the words and their frequencies, you would like to sort it according to the frequencies. This can be achieved if you create a list whose elements are tuples of two elements: the frequency of occurrence of a word and the word itself. For example, [(2, 'hi'), (1, 'what'), (3, 'is')]. Then the standard list sort will sort a list of tuples, with the tuples compared by the first element, and if these are equal, by the second element. This is nearly what is required in the problem.

Example:

Input: 9

hi

hi

what is your name

my name is bond

james bond

my name is damme

van damme

claude van damme

jean claude van damme

Output:

damme

is

name

van

bond

claude

hi

my

james

jean

what

your

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!