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
File formats are linked to certain programs.<br><br> True<br> False
Lostsunrise [7]
What was the answer?
7 0
3 years ago
Read 2 more answers
A poker hand consists of 5 cards drawn at random without replacement from a 52 card deck. Using python and the cards data frame
PSYCHO15rus [73]

Answer:

# Python program to shuffle a deck of card

# importing modules

import itertools, random

# make a deck of cards

deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club']))

# shuffle the cards

random.shuffle(deck)

# draw five cards

print("You got:")

for i in range(5):

  print(deck[i][0], "of", deck[i][1])

Output

You got:

5 of Heart

1 of Heart

8 of Spade

12 of Spade

4 of Spade

Explanation:

5 0
3 years ago
3.3 Code Practice: Question 1
Bezzdna [24]

Answer:

day=int(input(“Enter today’s day numerically: ”))

if(day ==15 or day ==30):

print(“It’s payday!”)

if(day !=15 and day !=30):

print(“Sorry, not a payday.”)

Explanation:Good luck!

6 0
3 years ago
It is important organic mineral that is found in the soil as ash​
loris [4]

Answer:

Calcium is the most abundant element in wood ash and gives ash properties similar to agricultural lime. Ash is also a good source of potassium, phosphorus, and magnesium.

7 0
2 years ago
Read 2 more answers
Which of the following is not a component of the programming phase of facility construction? deciding what to build examining sp
Anika [276]

Answer: designing the facility with architects.

Explanation: The programming phase of a facility construction has nothing to do with the architectural design of the facility. The programming phase usually involves ; Determining the needs of intended or impending users, estimated construction cost, required area for the project. The programming phase may involve individual or joint questioning or fact finding from the intended occupants or user group to determine their needs in terms of systems and infrastructure, security and so on. It also gets intended occupants informed on the features, use and design of the intended project. It also examines the effect of the project on structures previously existing in the environment.

4 0
3 years ago
Other questions:
  • When an instrument in the dashboard of your car informs you the air pressure in the right rear tire is low, what type of compute
    14·1 answer
  • 3. Which of the following is called address operator?<br> a)*<br> b) &amp;<br> c).<br> d) %
    12·1 answer
  • Are you allowed to copy and paste answers on brainy to give answers to other people?
    5·2 answers
  • Write an algorithm and flowchart to calculate sum of two given numbers​
    13·1 answer
  • How many sets of number do both Hex and RGB values have?
    10·1 answer
  • What is computer science​
    9·1 answer
  • Question 1 of 10
    15·1 answer
  • Samantha is part of a project management team working on the initiation phase of a project. What is her team expected to do in t
    5·2 answers
  • What type of software is developed by volunteers, contains code in the public domain, and helped to make Linux popular
    13·1 answer
  • Which programming language was released first? FORTRAN BASIC Perl Pascal<br><br>ANSWER: FORTRAN (A)
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!