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
Question 9. which describes an str?
Nadya [2.5K]
<span><span>STR stands for Short Term repeat. It is </span>a region of a DNA molecule that contains short segments of three to seven repeating base pairs</span>
<span>Hundreds of different types of STR's are found in the human genomes.</span>
3 0
3 years ago
4. Why isn't it realistic to market a new product using promoted tweets?
erica [24]

Answer:

Great question

Explanation:

is not realistic because nearly everyone doesn't even consider to look at the ad. Most people actually find it annoying when they are scrolling on their feed and all of a sudden an ad pops up.

3 0
3 years ago
Read 2 more answers
In order for storage devices to be prepared for use, they must be ____________ Group of answer choices pre-prepared loaded initi
svetlana [45]

Answer:

formatted

Explanation:

In order for storage devices to be prepared for use, they must be formatted.

7 0
3 years ago
Read 2 more answers
What are 3 data Gathering method that you find effective in creating interactive design for product interface and justify your a
ozzi

Answer:

In other words, you conducted the four fundamental activities that make up the interaction design process – establishing requirements, designing alternatives, prototyping designs, and evaluating prototypes.

Explanation:

5 0
2 years ago
What are some industries of aerodynamics and hydrodynamics? explain each one in detail.
maria [59]
Aerodynamic- Wind turbine, computational fluid dynamics, and Wind power

Hydrodynamics- Computational Fluid Dynamics, Hydraulics, and Microfluidics
3 0
2 years ago
Read 2 more answers
Other questions:
  • Identify the correct XHTML syntax for inserting an image as a hyperlink from the options provided. A. book.gif B. C. D.
    9·1 answer
  • Travis sends Suri what purports to be a link to an e-birthday card, but when she clicks on the link, software is downloaded to h
    11·1 answer
  • A python programmer is writing a function definition. What syntax should be used?
    6·1 answer
  • What is Patch tool ???<br><br>​
    15·2 answers
  • Which of the following is a real job title on The interactive media career pathway?
    6·2 answers
  • Kylee needs to ensure that if a particular client sends her an email while she is on vacation, the email is forwarded to a
    5·1 answer
  • What is Microsoft marketing ?
    10·1 answer
  • Complete the steps for adding a recurring event.
    10·1 answer
  • Many ____ classes for certification are available on the Internet and by many companies that have set up intranets within their
    15·1 answer
  • One way to protect against a security threat to a computer system is to __________. Avoid external links with inconsistent URLs
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!