Answered step by step
Verified Expert Solution
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
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
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