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

  Assume an n × n matrix a is given

Assume an n × n matrix A is given, containing only 1's and 0's, such that, in each row, all 1's come before all 0's. Give an O(n log n) algorithm to count all 1's in A.

  Let ll be a list of integers

Let LL be a list of integers. Use list comprehension to produce teh following lists. Each one should just take onel line. Anser questions as two comments.

  Improve the structural design - haunted house game

List the things you changed and the purpose of changing it. Good reasons include making code easier to read and easier to navigate when modifying it.

  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.

  When we sort a list of items, we need a basis

When we sort a list of items, we need a basis on which to compare the items to see whether one is bigger than another. If it's a list of numbers, Python just compares the numeric values; if it's a list of strings, Python compares the strings alpha..

  Write a python program that computes the mean, median, mode

How to write a python program that computes the mean, median, and mode?

  Cleint software so that it does not display

Rewrite the cleint software so that it does not display an echo of a message sent by the users. Maybe it means that each time a user tries to send a private message that same message is also sent back to them? summary: stop that from happening?

  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.

  Write a program that uses a bar

Write a program that uses a bar chart to display the percent-ages of the overall grade represented by the project, quizzes the midterm exam and the final exam

  The computer game function collision

The computer game function collision () checks whether two circular objects collide; it returns True if they do and False otherwise. Each circular object will be given by it's radius and the (x,y) coordinates of it's center.

  Program that creates a dictionary containing

Write a program that creates a dictionary containing the U.S. states as keys and their capitals as values. The program should then randomly quiz the user by displaying

  Programmer does not have to use the def statement

Unlike Z+-, the programmer does not have to use the DEF statement to create a variable. Instead, the programmer can simply use the variable. The first use of the variable creates it and initializes it to 0.

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