Question: Python Homework 8 Write a program that analyzes Charles Dickens's David Copperfield. Your program should scan the file copperfield.txt and provide per-chapter statistics for the
Python

Homework 8 Write a program that analyzes Charles Dickens's David Copperfield. Your program should scan the file copperfield.txt and provide per-chapter statistics for the total number of commas, total nber of words and average word length. In addition to these statistics, your program should report the longest and shortest word in each chapter. You should also create a list of all words used in the chapter. Sort the list alphabetically and report the first 10 words in the list. Finally, your application should create a dictionary that stores a count for each word appearing in the chapter. Use this dictionary to report the frequency of the longest word and shortest word. Also, report the most commonly occurring word in each chapter Extra Credit Create a dictionary that stores each of these statistics as a key-value pair (e.g., keys: title, commas, words, avgwordlength, shortword, longword, first10, last10, mostfreq). Then append each dictionary into a list so that I can quickly access each statistic using the following command print(chapterList[0]l'commas']) Hint When adding a key to a dictionary (named popularWords), the popularWords.setdefault(stripWord, 0) command will create a new key for the word only if there is no currently existing key for that word. This command also sets the initial value of that key to zero. Also, the popular Words.clear)can be used to reset your dictionary to an enpty dictionary Output Av raq word !ngth: 4.41564501990 11395 8horteat word: ' 6 Longest word: 'really-really-as',1 Last 10 words: youthful, yourself, your, younger,young, you?'.you.' you., you, you'11 Most popular word: ['he',170] gt,tistic for ch.pter 2 {1 ODJERvZ> ots1 mms: 574 Total vords: 6246 Average word length: 4-338072366314441 hortes word: 'a,145 iongest word: ['conplexion--confound' 11 F t. 10 word: "bwa 1 tehing, "good, "Fzwt.ty, "pretty . " , , "yu', , , {fer, (of, (the, (whun, (which Iast 10 words: youthful, youth, your, young, you?',you?, youi,you,you"d, you Host. popular word: 'h',250 SL4 1Les' fesz ehaipt.uz 63 A VSIQOR) Average word length: 1-210903126791277 shortest, word: ['i', 64] Longeat woxd: 'honeateat-helping 1 rirst 10 words: "bat "melancholy".,"our, remotelow".. "chank, "that's, "unfriended". c., (and Last 10 words: youth.. your, younger. young. you?'you,. you'ii, you d, you!, you Most popular word: ['the', 117 gt tistic for chapter 64 (A LAgT RETROSPECT Total words: 1652 Average word length: 4-37360774618402 short. word: t'i. 451 iongest word: "Copper-coloured',11 Last 10 worda: your, you."you,. you, yoxe!. yet.. yellow. years, year:. year Host popular word: 'and'.631
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
