Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Python 3

Do not import any package please

Q8: 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}

Hints:
Read in files using infile = open(filename), make sure that you are in the same directory.
Read each line by looping through with a simple for loop
Split the lines using line.split(" "), to get a list of the words
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.
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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92799173
  • Price:- $10

Priced at Now at $10, Verified Solution

Have any Question?


Related Questions in Computer Engineering

1 potassium metal is very reactive with liquid bromine the

1. Potassium metal is very reactive with liquid bromine. The result of the reaction is the formation of a white ionic solid. Explain what happens to these elements when they form an ionic compound and write the formula f ...

Assume you have been selected to build a system for

Assume you have been selected to build a system for Oil&Gas company. Do you prefer to build a win-based system or a web-based system? Why?

A confidence interval for a population mean is to be

A confidence interval for a population mean is to be estimated. The population standard deviation is guessed to be anywhere from 14 to 24. The half-width B desired could be anywhere from 2 to 7. Tabulate the minimum samp ...

For this problem assume the box contains 5 blue balls 7 red

For this problem, assume the box contains 5 blue balls, 7 red balls, and 6 white balls, and that we choose two balls at random from the box. What is the probability of neither being blue given that neither is red?

Task allocation and deallocation of mono-dimensional and

Task Allocation and deallocation of mono-dimensional and bi-dimensional arrays represented by pointers a. Declare and implement a function CreateArray(...) that returns a pointer to an array of n integers. b. Declare and ...

Question what system design methodologies and techniques

Question : What system design methodologies and techniques will you use? What potential risks do you see that may prevent successful completion of your solution design? The response must be typed, single spaced, must be ...

Compare and contrast static and dynamic efficiency applied

Compare and contrast static and dynamic efficiency applied to the fossil fuel market. Compare and contrast the concepts of resource rent and user cost as applied to this market and the potential differences in optimal ar ...

Junit test labyou will be creating a junit test class for

JUnit Test Lab You will be creating a JUnit Test Class for Gradebook.java, that has been provided for you.   Add a getScoreSize() method to the Gradebook class which returns scoresSize; Add a toString() method to the Gra ...

Inverse elasticityimagine youve started a new pizza

Inverse Elasticity: Imagine you've started a new pizza restaurant. It costs you about $3 to produce a pizza. Last week you sold 450 pizzas for $12 each. This week you raised your price and sold 300 pizzas for $16 each. W ...

Question what is the smallest value of n such that an

Question : What is the smallest value of n such that an algorithm whose running time is 1000n 2 runs faster than an algorithm whose running time is 4 n & on the same machine? Justify your answer. The response must be typ ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As