In: Computer Science
>>> words('example.txt')
['The', '3', 'lines', 'in', 'this', 'file', 'end', 'with', 'the', 'new', 'line', 'character', 'There', 'is', 'a', 'blank', 'line', 'above', 'this', 'line']
def cleanString(s): result = '' for c in s: if c not in '!,.:;?)': result += c return result def words(fileName): with open(fileName) as f: lines = f.readlines() result = [] for l in lines: for w in l.strip().split(): w = cleanString(w) if w != '': result.append(w) return result print(words('data.txt'))
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.