Question: Write Python statements that contains one function and a main program as follows: A) Write a Python function getWords() that takes a filename as parameter,

 Write Python statements that contains one function and a main program

Write Python statements that contains one function and a main program as follows: A) Write a Python function getWords() that takes a filename as parameter, reads whole file into a string, creates a new string by replacing all non-alphanumeric characters of this string with space character (thus keeping alphanumeric characters), and returns a list of words by splitting this string. B) Write a Python function countWords() that takes a list as parameter, and returns a dictionary that contains as keys the elements of the list and as values the number of occurences of the elements in the list. C) Write a Python function printDict() that takes a dictionary as parameter, prints the items (key - value pairs) on separate lines with a tab character between the keys and the values. D) In main program: 1) input a filename entered by the user, 2) call getWords() function to get the list of words in this file, 3) print the number of words, 4) sort the list, 5) call countWords() function with the sorted list to get a dictionary that contains counts of words, 6) print the number of distinct words (i.e. the size of the counts dictionary), 7) call printDict() function to print the words and their counts. Download and use the following text file

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!