Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Clean the resulting words getcleanwordList reads a file with given filepath and return a list of all words in the file with all the specified

image text in transcribedimage text in transcribedimage text in transcribed

Clean the resulting words getcleanwordList reads a file with given filepath and return a list of all words in the file with all the specified punctuation characters (,.!?;) removed (you might find the strip() function helpful). Note that all words are separated by whitespace characters, and a word contains only characters that do not include the following punctuation characters: , .!?;". Your code will need to split and strip the strings from the text file appropriately. For example, getcleanWordList("input3.txt", "..!?;") returns ["Hello", "Today", "is", "a", "lovely", "day", "isn't", "it"]. Hint: you need to call getallwords inside getcleanWordList. def getcleanWordList(filepath, charsToRemove): Read a file with given filepath, return a list of all words from the file with the specified characters that are stored in the string called charsToRemove are removed. Empty strings should not be added to the resulting list of cleaned words. return "stub" input3.txt Hello! Today is a lovely day, isn't it? def getallwords (filepath): Returns a list of all words from the given filepath. The function opens the file for reading, and closes the file before returning. result = [] f = open(filepath) for line in f: for word in line.strip ().split(): result.append (word) f.close() return result

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

Step: 3

blur-text-image

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

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions

Question

=+3. If you have identified impediments, how can you overcome them?

Answered: 1 week ago

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago