1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vinil7 [7]
3 years ago
10

Write a program that reads a book (a file in text format), breaks each line into words, strips whitespace and punctuation from t

he words, and converts them to lowercase. Count the total number of the words, the number of times each word is used, and print out the top 10 most frequently used words.

Computers and Technology
1 answer:
diamong [38]3 years ago
4 0

Answer:

Following are the code to this question:

file= open('book.txt') #open file

li= {} #define an empty list

for lines in file: # use for loop Split file data into words

   d= lines.lower().strip(' !?').split() #define variable d that Add it to map

   for val in d: #define loop to store data  

       if val not in li: #check value is not in list

           li[val] = 0 #define list and assign value in 0

       li[val] = li[val] + 1 #Sort the book data and add its value  

m = sorted(li.items(),key = lambda x : -x[1]) #sorted value into the m variable  

print(m[:10]) #print value

Output:

please find the attachment.

Explanation:

In the given python code first, we open the file "book.txt", in next line, an empty list is defined, that uses the for loop which can be described as follows:

  • In the for loop is used, that reads the file data, and defines a variable "d", that stores the values into the map.
  • In the next line another loop is used, that check file values, if values are the same type so, it adds values and writes it.  
  • In the last line, m variable is used, that sorts the values and use the slicing to print its value.

You might be interested in
What is the google search operator that limits results to a specific domain?
IrinaK [193]

Answer:

 Google search operator is also known as advanced operator which extend the various capabilities of the regular type of text searches. It basically contain various types of special characters and the commands.

Google search operator are very useful in the various technical and the content searches. This type of search operator also limits the result in the sites which are indexed with a specific domain and URL (User resource locator). The google search basically allow to use various symbols that are based on the operator.  

7 0
2 years ago
When describing memory, ____________ is the first component required in the process necessary for retention?
8_murik_8 [283]
Depends on how deep you're willing to go to really,
You need one of a few arrangements of flip flop circuits to keep 1-bit state.
Going deeper, you need either NAND, or NOR gates(or a bunch of other ones) and connectors.
Even deeper, you'll require diodes or transistors to build the logic gates.
Beyond that is particle physics.
8 0
3 years ago
Transaction processing systems (TPSs) provide valuable input to management information systems, decision support systems, and kn
nadezda [96]

A transaction is a simple task carried out as part of corporate operations. Transaction processing systems (TPS) handle business transactions for the corporation, supporting overall enterprise operations.

A TPS creates papers pertaining to a non-inquiry transaction and records the transaction itself, together with all of its results, in the database.

Today, TPS are required for business operations in practically every firm. TPSs feed information into organizational databases; they also serve as the framework for management-oriented information systems. Source data automation frequently involves direct data entering. Electronic data interchange is being utilized by transaction processing systems more and more. These systems offer computer-to-computer communication without the need for repeated data entry by substituting paper documents with formatted transaction data sent over telecommunications networks.

Learn more about information here-

brainly.com/question/15709585

#SPJ4

5 0
1 year ago
Describe a situation in which you have experienced harm as a consequence of a failure of computer security. Was the failure mali
frutty [35]

Answer: The goals of computer security are to protect computers and users from data theft or loss as well as damage to any part of the computer.

Explanation: Common means of achieving computer security are firewalls, anti-virus software and this can fail due to hardware problems  or   weaknesses that prevent malicious attacks.

To answer this question, think of a time when you experienced any one of these. For example, personally, I was once an unfortunate victim of a general malicious attack that took advantage of a weakness in my anti-virus software. After clicking on a link on a dodgy website, a virus was installed on my computer. My computer finally crashed, without any hope of restarting it. I lost all my data and I had to buy a new computer.  This was a malicious attack.

However, sometimes people can be specifically targeted to steal their data or monitor their activities.  

7 0
2 years ago
Write a C++ function with the following signature: void readAndConvert() The function takes no parameters and returns no value.
shepuryov [24]

Answer:

The function is as follows:

void readAndConvert(){

   int n; string symbol,name;

   cin>>n;

   cin>>symbol;

   cin.ignore();

   getline (cin,name);

   vector<string> trades;

   string trade;

   for (int inps = 0; inps < n; inps++){

       getline (cin,trade);

       trades.push_back(trade);}

   

   cout<<name<<" ("<<symbol<<")"<<endl;

   for (int itr = 0; itr < n; itr++){

       string splittrade[3];        int k = 0;

       for(int j=0;j<trades.at(itr).length();j++){

           splittrade[k] += trades.at(itr)[j];

           if(trades.at(itr)[j] == ' '){

               k++;    }}

cout<<splittrade[2]<<": "<<floor(stod(splittrade[1]) * stod(splittrade[0]))<<endl;        }

   }

Explanation:

See attachment for complete program where comments are used to explain each line

Download cpp
4 0
2 years ago
Other questions:
  • What are the 5 general terms of the fair use rule
    9·1 answer
  • To say the internet has helped democratize knowledge means that
    11·1 answer
  • How did the invention of the printing press lead eventually to an increase in the diversity of religious expression?
    7·1 answer
  • What is text box and label control​
    10·2 answers
  • Write a program to complete the task given below: Ask the user to enter any 2 numbers in between 1-10 and add both of them to an
    8·1 answer
  • The acronym pies is used to describe improvised explosive devices (ied) components. pies stands for:
    13·2 answers
  • Which job role requires you to create user guides for computer products and services?
    11·1 answer
  • Arrays of structures ________. Group of answer choices None of the above. are automatically passed by reference cannot be passed
    6·1 answer
  • What was the name of the first personal computer and what year was it introduced
    7·1 answer
  • terms found in provider documentation (e.g., difficult, extensive, or unusual) would support adding modifier to a cpt code.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!