Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

Explain the purpose of a spacer layer in surface micromachining?

Answered: 1 week ago

Question

6. Describe turning points in intercultural friendships.

Answered: 1 week ago