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
Jin needs to add a row into his spreadsheet, but he does not want to remove any existing data. Which combination of options shou
disa [49]

Answer:

b. insert > entire row

5 0
4 years ago
Read 2 more answers
WILL THUMBS UP!!!!!ALL COMMENTS!!!!!!
Mariulka [41]
True

the Articles of Confederation are finally ratified. The Articles were signed by Congress and sent to the individual states for ratification on November 15, 1777, after 16 months of debate. Bickering over land claims between Virginia and Maryland delayed final ratification for almost four more years. Maryland finally approved the Articles on March 1, 1781, affirming the Articles as the outline of the official government of the United States. The nation was guided by the Articles of Confederation until the implementation of the current U.S. Constitution in 1789.
4 0
3 years ago
A ____ is a synonym for a virtualization application.
forsale [732]

hypervisor is the answer

3 0
4 years ago
2. What is the layout of the modern keyboard known as?
lukranit [14]

Answer: QWERTY

Explanation:

QWERTY is a keyboard design for Latin-script alphabets. The name comes from the order of the first six keys on the top left letter row of the keyboard ( Q W E R T Y )

6 0
3 years ago
TRUE or FALSE: CSS is used to style web pages.
nirvana33 [79]

Answer:

true

Explanation:

HTML is the structure and CSS is the design

3 0
3 years ago
Other questions:
  • How can you tell if a hacker has administrative access?
    15·2 answers
  • How can ASCII be used to represent characters in a computer system?
    15·1 answer
  • Which of these is an advantage of using the Clipboard task pane? A. You are able to apply OLE easily. B. There are more paste op
    15·2 answers
  • Who is known as the father of computer? ​
    6·2 answers
  • How to turn off new macbook pro when it is frozen 2017
    11·2 answers
  • If your computers normal zoom is 100, but it looks like its at 500, how do you stop that? my invisioned thing isn't on, neither
    9·1 answer
  • Linux implements _________ to determine how a user is to be authenticated and whether there are password policies associated wit
    11·1 answer
  • Maria wants to create an image for a Web page. Maria should use _____. help me
    8·2 answers
  • FREE BRAINLIEST!!!!
    7·2 answers
  • Suppose that the first goal in a GP problem is to make 3 X1 + 4 X2 approximately equal to 36. Using the deviational variables d1
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!