Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Do not import any package please War and Peace Your challenge for this problem is to create a function dictify that takes in

Python 3 Do not import any package please War and Peace
Your challenge for this problem is to create a function dictify that takes in 1 argument: book_name. 
book_name: the string that is the name of the file to open

return: a dictionary containing the count of each length of word in sorted order. Eg. How many words total of length 1, 2, 3...?

Your output should look like (we cut out most of the dictionary): {6: 48342, 15: 254, 23: 2}

I started this problem with

def dictify(book_name): text = open(book_name).read().split() result = [] for word in text: length = len(word)

I do not what to do next?

Hints:

Since the book is long and complex, you might get zero length words (some tabs and spaces). Make sure to filter those out of your dictionary!

Your output dictionary should have its keys in sorted order, so {1: xxxx, 2: xxxxx, 3: xxxxx ...}

War and Peace. Part 2

Your challenge for this problem is to create a function process_book that takes in 2 arguments: book_name and mode.

def process_book(book_name, mode):

book_name: the string that is the name of the file to open
mode: a string that is either "average" or "median"
return: the "average" word length in the book or the "median" word length in the file, depending on the second argument.
Hint: We got a median word length of 4 for War and Peace.

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

Step: 3

blur-text-image

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

5. How would you describe your typical day at work?

Answered: 1 week ago

Question

What are oxidation and reduction reactions? Explain with examples

Answered: 1 week ago

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago