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
Svetradugi [14.3K]
3 years ago
5

Write a function wordcount() that takes the name of a text file as input and prints the number of occurrences of every word in t

he file. You function should be case-insensitive so 'Hello' and 'hello' are treated as the same word. You should ignore words of length 2 or less. The results printed will be ordered from the most frequent to the least frequent. Hint: dictionary and list. Test your implementation on file great_expectations.txt
Computers and Technology
1 answer:
artcher [175]3 years ago
4 0

Answer:

Explanation:

The following Python program uses a combination of dictionary, list, regex, and loops to accomplish what was requested. The function takes a file name as input, reads the file, and saves the individual words in a list. Then it loops through the list, adding each word into a dictionary with the number of times it appears. If the word is already in the dictionary it adds 1 to its count value. The program was tested with a file named great_expectations.txt and the output can be seen below.

import re

def wordCount(fileName):

   file = open(fileName, 'r')

   wordList = file.read().lower()

   wordList = re.split('\s', wordList)

   wordDict = {}

   for word in wordList:

       if word in wordDict:

           wordDict[word] = wordDict.get(word) + 1

       else:

           wordDict[word] = 1

   print(wordDict)

wordCount('great_expectations.txt')

You might be interested in
What is an example of constructive criticism for an employee who is shy during meetings?
rewona [7]
<span>Speak up more so people don't think you're rude</span>
8 0
3 years ago
Read 2 more answers
Change the following sentences using 'used to
Alinara [238K]

Answer:

a. We <u>used to</u> go to school together.

b. How did you <u>use to</u> spend the winter evenings?

c. We <u>used to </u>have our milk delivered.

d. I <u>used to</u> be in love with him.

e. At one time there <u>used to</u> be trees in the garden.

5 0
3 years ago
Ashley wants to know the oldest form of both water purification and waste disposal. Help Ashley determine the methods. The oldes
polet [3.4K]

Answer: Distillation and Landfill

Explanation:

Distillation is the old method of water purification, these process involves the separation of compounds or components of a mixture based on their different boiling points. Today we have advanced method of seperation, although Distillation is still being used.

Land fill is one of the oldest form of waste disposal, these method involves digging up a large land mass(depending on the waste to be disposed) and dumping the water into the dugged land mass, then cover it up with the sand that was dugged out. Today, they are more advanced ways to handle wastes such as incinerator.

3 0
3 years ago
Complete the body of the decrement static method using only the NaturalNumberKernel methods (multiplyBy10, divideBy10, and isZer
Ivan

Answer:true

Explanation:mark as brainliest

6 0
3 years ago
You are creating a story map about Mexico. After configuring the web app template, you launch the app to test it. When the app o
navik [9.2K]
Nbdjsksjsidjdjwkwejd
3 0
3 years ago
Other questions:
  • What is <br> Warehouse schema.
    14·1 answer
  • It is okay to use a dust rag when cleaning the inside of a computer.
    9·2 answers
  • When is the bond between the actin and myosin head is broken? when an ATP molecule binds to the myosin head when an ATP molecule
    6·1 answer
  • To copy the formatting of one control to other controls, use the ____ button on the form design tools format tab.
    7·1 answer
  • What is the aperture and how does it impact sunrise/sunset photos? What is generally considered an ideal aperture for sunrise/su
    5·2 answers
  • What are two constraints that continuous-media files have that conventional data files generally do not have?
    12·1 answer
  • Debbie’s colleague hasn’t provided her the required details to complete an important report. She is upset by this, and she sends
    14·2 answers
  • A user is attempting to format a 4 TB HDD using NTFS but only has the option to format the disk with a size of approximately 2 T
    15·1 answer
  • Suppose that a computer has three types of floating point operations: add, multiply, and divide. By performing optimizations to
    7·1 answer
  • Another way to create a new presentation is from the Home tab
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!