Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

Explain the market segmentation.

Answered: 1 week ago

Question

Mention the bases on which consumer market can be segmented.

Answered: 1 week ago