Write a program that counts the frequencies of each word

Assignment Help Python Programming
Reference no: EM13168320

Write a program that counts the frequencies of each word in a text, and output each word with its count and line numbers where it appears. We define a word as a contiguous sequence of non-white-space characters. (hint: split()) Note: different capitalizations of the same character sequence should be considered same word, e.g. Python and python, I and i. The input will be several lines with the empty line terminating the text. Only alphabet characters and white spaces will be present in the input. The output is formatted as follows:

 

Each line begins with a number indicating the frequency of the word, a white space, then the word itself, and a list of line numbers containing this word.

 

Sample Input

 

Python is a cool language but OCaml

is even cooler since it is purely functional

 

 

 

Sample Output

 

3 is 1 2

1 a 1

1 but 1

1 cool 1

1 cooler 2

1 even 2

1 functional 2

1 it 2

1 language 1

1 ocaml 1

1 purely 2

1 python 1

1 since 2

 

 

Reference no: EM13168320

Questions Cloud

Using jflab find a linear grammar for the language : The language L= {a n b m : n?m} is context free. Using JFlab find a linear grammar for the language.
Cost structure-service characteristics and competition : Describe the air carriers industry in terms of cost structure, service characteristics, competition.
How many grams of aluminum chromate are produced : How many grams of aluminum chromate are produced from 66.4 grams of aluminum hydroxide?
Calculate the number of nacl formula : calculate the number of NaCl formula units formed when 190 Na atoms and 98 Cl2 molecules react? 2Na + Cl2 → 2NaCl
Write a program that counts the frequencies of each word : Write a program that counts the frequencies of each word in a text, and output each word with its count and line numbers where it appears. We define a word as a contiguous sequence of non-white-space characters.
Major commodities transported by pipelines : What are the four major commodities transported by pipelines?
Predict the formula of the compound the ions produce : Using condensed electron configurations and Lewis electron-dot symbols to depict the monatomic ions formed from each of the following reactants, predict the formula of the compound the ions produce. N and Mg
Calculate the mass of lead nitrate that had to be added : Sodium nitrate was added to 2.0 L of water at 25 °C to produce a saturated solution. The solution was then heated to 80 °C. Calculate the mass of lead nitrate that had to be added to produce a saturated solution at that higher temperature.
Pragmatically savvy : Below are descriptions of four university professors. Hopefully you will never have an instructor like  any of them because they are not very pragmatically savvy.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

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