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
Who destroys all the program data files etc of computer​
Anna71 [15]

Answer:

anonymous gang desroy all the program data and computer

3 0
4 years ago
Read 2 more answers
Which of the following are disadvantages of networks? Check all of the boxes that apply.
RideAnS [48]

Answer:

• Network intruders can access all computers on a network.

• Networks are costly to set up.

Explanation:

A network can be defined as a connection between the internet and the computer. A network is a means by which information or data are transmitted from one computer to another.

We have various types of networks and some of them are:

a) Local Area Network (LAN)

b) Wireless Local Area Network (WLAN)

c) Wide Area Network (WAN)

d) Campus Area Network (CAN)

e) Metropolitan Area Network (MAN)

f) Personal Area Network (PAN) e.t.c

The disadvantages of network are:

a) Network intruders such as computer hackers can easily access all computers on a network.

b) Networks are costly to set up.

It is of outermost importance that a network used by a computer is secured using security such as encryption in other to prevent data loss , hackers and exposure of information that are sensitive to computer users.

4 0
3 years ago
What is the mass of a cookbook
tatiyna

Answer:

it varies on the size of the cookbook

Explanation:

6 0
3 years ago
A(n) ____cookie is created by an ad on a website, where the ad is owned and managed by a
mart [117]

Answer:

Third-party cookies

Explanation:

4 0
3 years ago
In fat 12, how many bytes does each directory-entry use to define a file or subdirectory in a directory?
Paladinen [302]
If I've got it correct, in FAT12, each directory-entry use 2 bytes to define a fire or subdirectory in a directory. It's a field that called the First Logical Cluster that is needed to specify where the file or subdirectory begins. Is the value of the First Logical Cluster is "0", then it refers to the first cluster of the root directory.
6 0
4 years ago
Other questions:
  • Renee just got on the freeway to go to her cousin's house in Denver. She is driving 50 miles per hour. Her sister Kim left one h
    12·1 answer
  • Joe is a computer service technician. People in his neighborhood usually depend on his suggestions for purchasing any computer a
    9·2 answers
  • What term identifies the physical interface between a computer and its peripherals?
    5·1 answer
  • ___ a Word object in an Excel worksheet to activate the Word features. A. Ctrl-click. B. Shift-click C. Double-click D. Click
    15·2 answers
  • Declared inside a function and is only available within the function in which it is declared.
    13·1 answer
  • Once we have reached complete efficiency in the third part of the LRAS Curve, what occurs?
    10·1 answer
  • What is LINUX?
    6·2 answers
  • The Next Einstein Initiative and the ________ Institute for Mathematical Sciences bring bright young learners and the best lectu
    15·1 answer
  • Alguien me podria ayudar a hacer este codigo porfavor? en php Desarrolle el código que solicite los datos (desde teclado) Nombre
    10·1 answer
  • Which tool is used to see the wireless networks in a given area?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!