Question: python question wordfreq.py punctuation = '~!@#$%^&*()_+{}|: ?`=[];',./' filename = 'grimm.txt' book = open(filename).read() bookNoPunct = book.translate(str.maketrans('','',punctuation)) words = bookNoPunct.split() wordfreq = {} for word in
python question
wordfreq.py
punctuation = '~!@#$%^&*()_+{}|:"<>?`=[]\\;\',./' filename = 'grimm.txt' book = open(filename).read() bookNoPunct = book.translate(str.maketrans('','',punctuation)) words = bookNoPunct.split() wordfreq = {} for word in words: if word not in wordfreq: wordfreq[word] = 0 wordfreq[word] += 1 Modify the code above to.... d) Ignore case (upper/lower) when counting words. e) Read from the file: LifeOfBrian.txt. f) Ignore numbers when counting words. g) Print out the total number of words in the file, and the number of unique words in the file. h) Print out the words and their frequencies.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
