Create an empty dictionary called word_frequency

Assignment Help Computer Engineering
Reference no: EM132113568

Python script how do I do this?

Specification

Create a script that does the following

Reads in a text file

Creates a dictionary of word frequencies

In this dictionary they keys will be words found in the file

The values would be the number of times the word appeared

Prints a sorted list of all words in the file and how many times they appeared in the file

In the frequency dictionary, the keys would be individual words and the values would be the number of times the word appeared in the file.

This script must contains two functions.

word_frequencies_create

word_frequency_print

word_frequencies_create

This function must have the following header

def word_frequencies_create(filename):
This function should read in a text file and return a word frequency dictionary.

A word frequency dictionary is one where the keys are words and the values are the number of times the word appears in the file.

This function must ignore case, so "We" and "we" should count as the same word.

word_frequency_print

This function has the following header

def word_frequency_print(frequencies):
This function must print the words in alphabetical order along with the number of times each word appears in the file.

Test Code

The script must contain the following test code at the bottom of the file

word_freq = word_frequencies_create('xxxxxxx') word_freq = word_frequencies_create('gettysburg.txt') word_frequency_print(word_freq)
Suggestions

1. Write this script in stages, testing your script at each step

2. Create a file with the hashbang line, the test code and each function. The body of the function should be the Python statement pass which does nothing but it stops syntax errors.

3. Remove the pass statement in word_frequencies_create and replace it with code that opens a file for reading. If the file cannot be opened for reading, the code should print an error message and not do any further processing of the file.

4. Create an empty dictionary called word_frequency. After this statement write a for loop that prints each line in the file.

5. Use the lower string method to change all capital letters in the string to lower case.

6. Use the split string method to create a list of all the words in the file. Print this list.

7. Remove the previous print statement. In its place write a for loop that prints each word in the list.

8. Write an if statement that checks whether the word is already in the dictionary. If not add this word to the dictionary with the value 1. Outside both for loops, print the dictionary.

9. Add an else clause to the if statement that adds 1 to the value associated with the word.

10. Remove the print statement from the end of the function. Replace it with a statement that returns the word_frequencies_create dictionary. Remove the pass statement from word_frequency_print and replace it with a statement that prints the parameter frequencies.

11. Replace the print statement with a for loop that prints the word and word count value for each word in the dictionary.

12. Change the for loop so it prints the words in alphabetical order.

Reference no: EM132113568

Questions Cloud

A program to display the amount of the discount : Write a program that asks the user to enter the nmber of packages purchased. the program should then displa the amount of the discount.
Prepare a module that has the functions and caller program : Consider the three words: STAM, TRAM,PRAM. Find the union, intersection, difference (STAM,TRAM) using arguments.
Write a read_temperature_data function that take in the name : Write a read_temperature_data function that takes in the name of a file as filename. Return a list with all of the temperature values.
A program to asks the user to enter integers : Write a Python program that does the following: asks the user to enter integers - they can indicate they are finished by typing DONE.
Create an empty dictionary called word_frequency : Write an if statement that checks whether the word is already in the dictionary. Create an empty dictionary called word_frequency.
Process for creating a random sample of size : Which of the following describes a correct process for creating a random sample of size 20 from a numbered list of 10,000 individuals? Check all that apply.
Create an application to help track donations : The local humane society has asked you to create an application to help track donations.
Write a function gcd that return the greatest common divisor : Write a function gcd(a, b) that returns the greatest common divisor of the parameters a and b.
What percentage of returns were greater than 20 percent : What percentage of returns were greater than 20 percent?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd