Write a Python program that does all the following steps: Read a file located in the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a Python program that does all the following steps: Read a file located in the same directory as the program named: cs521_5_5_input.txt o Print a clear error message and end the program if the file is missing o The program must not crash because the file doesn't exist . Your program will have four main objectives: o Determine the file's length in words o Count the number of unique words in the file o Return the word(s) that is/are most frequent o Return the word(s) that is/are least frequent To accomplish these four objectives, you will create the following user-defined functions: make_word_list() make_unique() Has a single parameter, a file object Iterate through the file and extract every word from the file Strip from each word any punctuation Returns a list object of the words . Has a single parameter, a list object of all words in the file (created via the make_word_list() function) find most frequent() . From the list object, create a list of only unique words Returns a list object of the unique words Has a single parameter, a list object of all words in the file (created via the make_word_list() function) From the list object, count the occurrence of each word and create a list object that stores the word(s) that appear(s) the most often Returns the list object of the most frequent word(s) find_least frequent() Has a single parameter, a list object of all words in the file (created via the make_word_list() function) From the list object, count the occurrence of each word and create a list object that stores the word(s) that appear(s) the most often Returns the list object of the least frequent word(s) Sample Output: The file has 50 words in total. The file has 27 unique words in total. The least frequent word (s): ['circumstance', 'world'] The most frequent word (s): ['my', 'a', 'the', 'to', 'yes', 'no', 'he', 'she', 'it', 'there'] Notes: You may NOT use a dictionary object to solve this problem. You should consider words as non-case sensitive. Meaning, the word “Hello” is the same as "hello". Account for this accordingly as you determine unique words, most and least frequent words somewhere in your function(s). Do not hardcode your string slices. Remember to properly close all files. Write a Python program that does all the following steps: Read a file located in the same directory as the program named: cs521_5_5_input.txt o Print a clear error message and end the program if the file is missing o The program must not crash because the file doesn't exist . Your program will have four main objectives: o Determine the file's length in words o Count the number of unique words in the file o Return the word(s) that is/are most frequent o Return the word(s) that is/are least frequent To accomplish these four objectives, you will create the following user-defined functions: make_word_list() make_unique() Has a single parameter, a file object Iterate through the file and extract every word from the file Strip from each word any punctuation Returns a list object of the words . Has a single parameter, a list object of all words in the file (created via the make_word_list() function) find most frequent() . From the list object, create a list of only unique words Returns a list object of the unique words Has a single parameter, a list object of all words in the file (created via the make_word_list() function) From the list object, count the occurrence of each word and create a list object that stores the word(s) that appear(s) the most often Returns the list object of the most frequent word(s) find_least frequent() Has a single parameter, a list object of all words in the file (created via the make_word_list() function) From the list object, count the occurrence of each word and create a list object that stores the word(s) that appear(s) the most often Returns the list object of the least frequent word(s) Sample Output: The file has 50 words in total. The file has 27 unique words in total. The least frequent word (s): ['circumstance', 'world'] The most frequent word (s): ['my', 'a', 'the', 'to', 'yes', 'no', 'he', 'she', 'it', 'there'] Notes: You may NOT use a dictionary object to solve this problem. You should consider words as non-case sensitive. Meaning, the word “Hello” is the same as "hello". Account for this accordingly as you determine unique words, most and least frequent words somewhere in your function(s). Do not hardcode your string slices. Remember to properly close all files.
Expert Answer:
Answer rating: 100% (QA)
import os def makewordlistfileobject Extracts every word from the file object stripping any punctuation Args fileobject A file object Returns A list o... View the full answer
Related Book For
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall
Posted Date:
Students also viewed these programming questions
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
inary Differential Equations > Assessment 10.1-10.2 Score: 0.25/3 1/3 answered "X" Question 2 < Submit Question > Gradebook Convert the differential equation `u" -3 u' -4 u = e^(-t)` into a system of...
-
Show that of all the isosceles triangles with a given perimeter, the one with the greatest area is equilateral.
-
This output summarizes a simple regression fit to the data on marketing Courier Paks in Example 25.1. (a) Summarize the estimated equation of the simple regression model. (b) The t-statistic for the...
-
Patty Hayes owned four Personal Seat Licenses (PSLs) at the Cleveland Browns Stadium. Hayess PSLs reserved four seats on the 50-yard line, at the railing, on the north side of the stadium. As the...
-
Dunn Inc. owns and operates a number of hardware stores in the New England region. Recently, the company has decided to locate another store in a rapidly growing area of Maryland. The company is...
-
You invest $300,000 for new equipment at a manufacturing facility. The equipment is expected to produce $125,000 per year in revenue. The expenses for operating the equipment are $45,000/year. There...
-
b. Prepare all consolidating entries needed to prepare consolidated statements for 20X5. (If no entry is required for a transaction/event, select "No journal entry required" in the first account...
-
1. Equation: x +9 = 0 Is x=3i a solution to this equation?
-
Define the employment relationship and discuss the changes that have taken place to the relationship in recent years.
-
Utilitarian Jeremy Bentham argued that if utility is good, then it is good irrespective of whose utility it is, and thus the sum of societal utility should be maximized. In what ways do you feel this...
-
What is the source of energy for the building you are in or closest to? What barriers prevent more energy from being obtained from clean sources?
-
What is an evidence- based intervention? Why is it important to adopt evidencebased interventions? What factors might you need to consider in adopting an evidence- based intervention?
-
Rawls (1999, 205) writes that if government is assumed to aim for the common good, and if "some men can be identified as having superior wisdom and judgment, others are willing to trust them and to...
-
The table below shows Southern Rock Bank's balance sheet in the form of a T-account: ASSETS LIABILITIES and BANK CAPITAL Government bonds $200 million Deposits $550 million Loans $620 million Bonds...
-
Swifty company is a publicly held corporation whose $1 par value stock is actively traded at $30 per share. The company issued 3400 shares of stock to acquire land recently advertised at $93000. When...
-
Western Animal Rescue is a nonprofit organization that supports the fostering and adoption of animals, such as cats, dogs, and birds. People can register to adopt animals. Others register and add...
-
Describe how prototyping can be used to augment the traditional SDLC.
-
Alice in the human resources department at the Cho Manufacturing plant is constantly being asked by employees how much is taken out of their paychecks for insurance, taxes, medical, mandatory...
-
For coordinates \(\left(x^{1}, x^{2} ight)\) and metric \(g=\operatorname{diag}\left(g_{11}, g_{22} ight)\), the Gaussian curvature is For a sphere with coordinates defined in the following figure,...
-
Consider the holonomic basis defined in Box 26.1 . Using that the tangent vector for a curve can be written \(t=t^{\mu} e_{\mu}=\left(d x^{\mu} / d \lambda ight) e_{\mu}\), show that Thus, \(g_{\mu...
-
The Lie bracket of vector fields \(A\) and \(B\) is defined as their commutator, \([A, B]=\) \(A B-B A\). The Lie bracket of two basis vectors vanishes for a coordinate basis but not for a...
Study smarter with the SolutionInn App