Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the Design Recipe to write a function called word_frequency that consumes the name of a file (str) and produces a dictionary in which the

image text in transcribed

Use the Design Recipe to write a function called word_frequency that consumes the name of a file (str) and produces a dictionary in which the keys are the individual words found in the file and the values are the number of times each word appears For example, if the word "the appears 128 times, the dictionary would contain an element with 'the' as the key and 128 as the value The program may assume the file exists on disk and no error checking is needed. The file may be assumed to contain 1 word per line To test the given examples on your local computer, create a file named nums.txt and make sure its contents are 4 and create a file named chars.txt and make sure its contents are For example Test Result tilonamo "nums.txt" frequencies word frequency (ilename) rosult" for key in sorted (frequencies.keys()): rosult += str (koy) + " " + str(frouoncios[koy]) + " " print (result) filname "ma t t2.txt" froquencios = word-froquency (filonamo) result "" for key in sorted (frequencies.keys O): b 1 result += str (key) " " + + str(frequencies [key]) + " " print(result)

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

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions