Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have to write a Python program (3.5) which take two text files. Start with the wordfreq.py script . As presented, it only calculates the

You have to write a Python program (3.5) which take two text files. Start with the "wordfreq.py" script . As presented, it only calculates the frequency of each individual word in a text file, stored in a dictionary structure. Keep the input question that asks how many results you want displayed (n).

Note: Since youll be doing many of the same operations twice, you should revise the code to write some sensibly-designed reusable functions instead of simply duplicating each chunk of code and changing variable names.

Revise and enhance the program so that the program ALSO does these things:

1. Ask the user for a second text file to compare with the first one. Ill refer to the files A and B below.

2. Calculate the word frequency for text B in the same way it does for A.

3. For both files, compute and print out how many total words it contains and how many distinct words they contain.

4. For both files, print out the n most frequent individual words (sorted like the provided example already does), but also showing the percentage of the total words each represents in its file. This is simple to calculate, as: frequency_of_word / total_words * 100. Round that to 2 decimal places.

5. Last, as a simple comparison of the texts, your program should print all the words that occured more than once in text A but not at all in B and vice-versa.

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Shouhong Wang, Hai Wang

1st Edition

1612330150, 978-1612330150

More Books

Students also viewed these Databases questions

Question

Understand the principles of a learning organization.

Answered: 1 week ago

Question

=+Do you want to work from home?

Answered: 1 week ago

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago