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

  The integers should be printed in order with addresses

The integers should be printed in order with addresses from main. When the steps of the function order have been completed the smallest value will be stored in a, the middle in b, and the largest in c.

  Same directory as your program

In the same directory as your program, create a file FF1, and write into it Hello (with a space at teh end). Similarly, create a file FF2, and write into it world! (with a new line, i.e., an ENTER at the end). And create a file DD and write into i..

  We would like to implement the lexical order

We would like to implement the lexical order for lists. For simplicity, we only consider lists of numbers, where , >= have their usual meaning.

  Write a function rmduplic(l), where l is any list

Write a function rmDuplic(L), where L is any list. The function should return a list M that contains the same items as L, except that repetitions (duplicates) have been removed: only the first occurrence of each entry is kept (i.e., order is prese..

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

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

  A string is valid windows filename.

writing a function in python that verifies whether a string is valid windows filename.

  Specializes in solving the equations ax=b by doolittle''s dec

Write a  program that specializes in solving the equations Ax=b by Doolittle's decomposition method, where a is the HIbber matrix of arbitrary size nxn

  Design a function that accepts an integer

Design a function that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the function will return the sum of 1, 2, 3, 4, . . . 50. Use recur..

  Write a function comp(d1,u1,d2,u2)

Write a function comp(d1,u1,d2,u2)

  Program that allows the user to enter the type of coin

Create a program that allows the user to enter the type of coin to be evaluated and the number of coins. The program should calculate the total weight of the coins and the height of the coins when stacked. Name the program coins.py. Use the table bel..

  Data file is a comma separated

The data file is a comma separated text values stored in a file with '.CSV' extension. The file has five columns corresponding to employee data fields listed above.

  Function by sum of sines

code the program using an editor (DO NOT COMMAND LINE THE PROGRAM) and show the results

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