Question
Use python for the following problem. A function that will help you with set up (Using Lists) In this lab you will be reading a
Use python for the following problem. A function that will help you with set up (Using Lists)
In this lab you will be reading a variety of files containing text. I have three files you can use for testing purposes:
The preamble to the constitution (the smallest so a good starting point)
Green Eggs and Ham (mid-sized and fun to analyze)
Hamlet (Very large and a good way to see what happens as the problem grows)
In two different activities in this lab you will be analyzing the individual words in these text files. In both of those activities you will need to process the text file into these individual words. Thus, it might be helpful to have a piece of code that does that common prep work.
By the time you are done with this activity, I want you to have a function called createWordList() that:
takes a single string as a parameter which is assumed to be the name of a text file
opens the file for reading
reads that file either all at once (using read()) or one line at a time (using readline()). Either way, you will have a STRING, and you need to:
"clean up" punctuation by removing all of the following characters: .,!?;(){}:
(Note: To clean up the punctuation, take a look at the Python string method replace(). Notice how you can replace things you don't want with the empty string.)
"clean up" the dash "-" by replacing it with a space " ". (Some of the words, like "sam-I-am", should probably be counted as 3 words.)
converts everything to lowercase
splits it up based on words (remember, split gives you a LIST)
add each of these word to a word master list
return the final word master list.
and, the method itself is stored in a file called lab12.py
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started