Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions