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
Complete the given C program (prob1.cpp) to read an array of integers, print the array, and find the 2nd largest element in the
labwork [276]

Answer:

#include <stdio.h>

int getElement(int arr[], int size) {

   

   int largest2, largest = 0;

   for(int i=0; i<size; i++)

   {

       if(arr[i] > arr[largest])

       {

           largest = i;

       }

   }

   if(largest != 0)

       largest2 = 0;

   else

       largest2 = size - 1;

   for(int i=0; i<size && i != largest ;i++)

   {

       if(arr[i] > arr[largest2])

           largest2 = i;

   }

   

   return arr[largest2];

}

printArray(int arr[], int size) {

   

   printf("The array is: ");

   for(int i=0; i<size; i++)

   {

       printf("%d ", arr[i]);

   }

   printf("\n");

}

int main()

{

 

   int arr[5] = {30, 20, 5, 10, 24};

   printArray(arr, 5);

   printf("Second largest number is: %d", getElement(arr, 5));

   return 0;

}

Explanation:

Since you did not provide any code, I wrote it from the scratch. I also added the main function for you to check the result.

<em>printArray</em> function basically prints the element of the array

<em>getElement</em> function:

- Declare the two variables to hold the value for largest and second largest

- Inside the first loop, check if there is any number that is greater than largest, if yes, assign it to largest

- Inside the second for loop, check if there is any number that is greater than largest2, if yes, assign it to largest2 (Be aware that the largest we found in the first loop is excluded)

- Return the second largest

* Notice that we were able to apply this solution since the numbers are unique.

5 0
3 years ago
Write an overview of your opinion of Digital Access
Zepler [3.9K]

Answer:

Digital access is the ability to fully participate in digital society. This includes access to tools and technologies, such as the Internet and computers, that allow for full participation.  Unfortunately, not everyone has complete digital access and therefore, are not able to fully participate in digital society. The separation between those who have complete access and those who do not is referred to as the Digital Divide.

5 0
3 years ago
To view the preview pane, click the ____ tab, and click print on the navigation bar
Blababa [14]

To view the preview pane, click the "File" tab, and click print on the navigation bar.

I guess the word in the blank is File.

3 0
3 years ago
3) Many people use the World Wide Web (Web) regularly, and search engines
lara31 [8.8K]

Answer: See explanation

Explanation:

Navigational search - This occurs when the user is looking for a certain website. Then the name of the website will be entered into the search bar.

Informational search - This occurs when the user wants to get a certain information. For example, if user enters "what is computer" into the search bar, different results relating to the word "computer" will be gotten.

Transactional search - This occurs when the user wants a website that is interactive it which possess more interaction. An example is when the user wants to buying something, register for something or maybe download something

6 0
3 years ago
Head-mounted displays often use organic light emitting diode,or technology.
nydimaria [60]

Organic light emitting diode,

Technology is a category not a specific thing

7 0
3 years ago
Other questions:
  • Which sentences describe the use of web development tools?
    14·1 answer
  • A Venn diagram is used to show can somebody help plz
    7·2 answers
  • When conducting research on the internet, what is a starting point for determining how to start the research?
    5·1 answer
  • What are the preset formulas in a spreadsheet called?
    6·2 answers
  • What happens when you double-click a column border??
    12·1 answer
  • An aircraft departs an airport in the mountain standard time zone at 1615 MST for a 2-hour 15-minute flight to an airport locate
    14·1 answer
  • Describe what skills are required by the helpdesk technician for each step in a typical incident process.
    9·1 answer
  • Que papel tuvo la innovación en la propagación de la telefonía móvil?​
    7·1 answer
  • Which of the following are features of the HTTPS protocol?
    12·1 answer
  • A palindrome is a string that reads the same from left to right and from right to left. Design an algorithm to find the minimum
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!