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
Write your question here (Keep it clear and simple to get the best answer)
weeeeeb [17]
What is your favorite book?
4 0
2 years ago
Read 2 more answers
Suzanne is following a fad diet. She has started to experience low energy during her workouts, and on a recent trip to the docto
Nastasia [14]

Answer:

Hi mate....

Explanation:

This is ur answer....

<em>-</em><em>-</em><em>></em><em> </em><em>Suzanne just facing low carbohydrates</em>....

hope it helps you,

mark me as the brainliest pls....

Follow me!

5 0
2 years ago
Read 2 more answers
Assignment 2: Room area
Y_Kistochka [10]

Answer:

a = float(input("Enter Side A: "))

b = float(input("Enter Side B: "))

c = float(input("Enter Side C: "))

d = float(input("Enter Side D: "))

e = float(input("Enter Side E: "))

area1 = 1.0* a * b

area2 = (a - c) * (d - e -b)

area3 = 0.5 * (a - c) * e

print ("Room Area: " + str(area1 + area2 + area3))

Explanation:

happy to help ^3^

5 0
3 years ago
Pick a web browser (a leading one or perhaps a lesser-known one that you use) and examine the Privacy and Security features and
Veseljchak [2.6K]

Solution :

<u>Chrome web browser</u>

The Chrome web browser uses a range of privacy and security settings for its customers. They include several security indicators as well as malware protection. Chrome uses the sandboxing technology, which prevents the harmful viruses and Trojans from reaching the computers.

Chrome provides a safe browsing by giving us an alert whenever we try to browse some harmful web sites.  It also warns you if we use a username and password combination which has been compromised in any data leak.

Chrome also serves to protect the individuals :

It provides a features of Ad blocking.

When we want to browse safely without being recognized or without storing any credentials, Chrome provides an Incognito mode.

Many businesses can be done on the internet using Chrome platform that is safe and authenticate to gather and collect data and information.

3 0
3 years ago
The recheck document button, which resets the spelling and grammar checker to flag previously ignored errors, is located in the
kumpel [21]
The answer is b and c
7 0
3 years ago
Other questions:
  • What happens when the computer is thrashing? quizzlet?
    12·1 answer
  • Jackie is planning a birthday party for her little brother and is researching different trampoline parks. She receives a pop-up
    12·2 answers
  • Gina works in an SDLC team. When Gina makes changes to a file, no one else is allowed to acess it. Which type of version control
    10·1 answer
  • In 1988, Robert Morris, Jr. launched a program called the _________ that used weaknesses in e-mail programs and operating system
    5·1 answer
  • Options to open,save,and print a document are found on which of the following tabs? A.File B.Home C. Design D. Layout
    5·2 answers
  • Can change the tab colors of the worksheets in excel
    13·1 answer
  • D. DROP
    6·1 answer
  • Can someone tell me how to get rid of the the orange with blue and orange on the status bar
    14·2 answers
  • What should students hope to get out of classroom discussions? Check all that apply.
    10·2 answers
  • Why is a computer called"a computer"?​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!