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

 Use python for the following problem. A function that will help

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 createWordList0 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 read0) or one line at a time (using readline). Either way, you will have a STRING, and you need to o clean up" punctuation by removing all of the following characters (Note: To clean up the punctuation, take a look at the Pythor string method replace0. 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 o o return the final word master list. . and, the method itself is stored in a file called lab12.py For example, >>> words = createwordList("preanble.txt.) ["We', c','tranquility''provide' 'torthe'common','detene' "promote"th toourselves'andu.posterity."do''ordain 'and","establish "people', "of", .the' 'united'. 'states ', 'in', ,order", 'to', 'tbe", a "ore''perfect union'eatabiish''ustice'. 'insure''doneat 'f e". 'generai' 'uelfare', and.secure".the''blessings'of."1iberty. 'this''constitution'ortbeunited',s states' ofamerica' >>>len(words) 52 > words createWordList ("greeneggs.cxt" len (ords)

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!