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
The instructions in a program, when expressed in Python, ...
sergejj [24]

Answer:

can only be carried out by computers, as long as an interpreter is available which one is it?

Explanation:

The interperetor needed is called CPython, this is the standard C implementation of the language.

7 0
3 years ago
Which of the following is not a characteristic of a large database?
BartSMP [9]
C is the correct answer
8 0
3 years ago
Discuss the relationship amongst the following basic file elements: • Field. • Record. • File. • Database. • Directory.​
Gwar [14]

Answer:

describe two events from the life of the prophet that illustrate the way he treated non muslims3+15-75+375.

Explanation:

53+15-75+3756,1803+15-75+375describe two events from the life of the prophet that illustrate the way he treated non muslims

4 0
2 years ago
What is an border in html
kompoz [17]

Borders can be applied to most HTML elements within the body. To make a border around an element, all you need is border-style . The values can be solid , dotted , dashed , double , groove , ridge , inset and outset . border-width sets the width of the border, most commonly using pixels as a value.

8 0
3 years ago
25 POINTS!!!!!!!!!!!!!
Paladinen [302]
A leaking data exhaust
7 0
3 years ago
Read 2 more answers
Other questions:
  • What dose it need For a device to be considered a kind of computer
    14·2 answers
  • Which type of security personnel may work for government as well as for private security agencies?
    7·2 answers
  • Sizing handles are used in Microsoft® Word® to _____.
    13·1 answer
  • Match the items.
    15·1 answer
  • I want to customize my company's logo, name, address, and similar details in all my business documents what option should use?
    12·1 answer
  • . Stress can affect not only your health, but also other aspectsof your
    15·1 answer
  • Describe how you would define the relation Brother-in-Law whose tuples have the form (x, y) with x being the brother-in-law of y
    9·1 answer
  • Careers in information technology deal with
    12·2 answers
  • If you misspell a word in your Java program it may be true that I. the program will not compile II. the program may compile, but
    6·1 answer
  • You respond to a fire at a pharmaceutical production plant. One of the outside storage tanks is on fire. The placard on the tank
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!