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
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