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
Suppose that the splits at every level of quicksort are in the proportion 1 − α to α where 0 < α ≤ 1/2 is a constant. Show th
Lady_Fox [76]

Answer:

Explanation:

The minimum depth occurs for the path that always takes the smaller portion of the

split, i.e., the nodes that takes α proportion of work from the parent node. The first

node in the path(after the root) gets α proportion of the work(the size of data

processed by this node is αn), the second one get (2)

so on. The recursion bottoms

out when the size of data becomes 1. Assume the recursion ends at level h, we have

(ℎ) = 1

h = log 1/ = lg(1/)/ lg = − lg / lg

Maximum depth m is similar with minimum depth

(1 − )() = 1

m = log1− 1/ = lg(1/)/ lg(1 − ) = − lg / lg(1 − )

4 0
3 years ago
In comparing a computer to the human brain, the computer's hardware is like _____ and the computer's software is like _____.
Ne4ueva [31]
This includes application software<span> such </span>as<span> a word processor, which enables a user to perform a task, and system </span>software<span> such </span>as<span> an operating system, which enables other </span>software<span> to run properly, by interfacing with hardware and with other </span>software<span>.
</span>
Computer hardware<span> is the collection of physical parts of </span>a computer system<span>. This includes </span>the computer<span> case, monitor, keyboard, and mouse. It also includes all the parts inside </span>the computer<span> case, such </span>as<span> the hard disk drive, motherboard, video card, and many others. </span>Computer hardware<span> is what you can physically touch.


</span>
8 0
3 years ago
If cos 3/5 what is the sin and tan​
suter [353]

Answer:2.988584094

Explanation:

6 0
3 years ago
Suppose we have a relation schema R(A, B, C) with FD A rightarrow B. Suppose also that we decide to decompose this schema into S
4vir4ik [10]

Answer:

Check the explanation

Explanation:

A relation schema is the fundamental schema for a table. Which is In a relational kind of database (what individuals naturally refer to when they talk about database) each take can be referred to as a "relation" . therefore a relational schema is the design for the table.

kindly check the attached image below to see the step by step solution to the question.

7 0
3 years ago
THESE ARE GAME DESIGN QUESTIONS PLEASE TRY TO ANSWER THESE QUESTIONS AS BEST TO YOUR KNOWLEDGE, THANK YOU ALL FOR EVERYTHING YOU
Setler79 [48]

1. The purpose of an action game is to provide an alternate reality where you have opportunity to pursue adventure. The purpose of a trivia game is to have fun while answering questions, perhaps with a trace of competitivity. Since the games are in different genres, the purposes of the games are different; trivia games are oftentimes simpler in function, while action games require more involvement and of course, action.

2. Some games are easier to play with two people, like games that require teamwork. However, others are more conveniently played by yourself. For example, Ge0metry Dash should be played by yourself, but games like F0rtnite can be more easily played in teams. However, there are also games that can be played both by oneself and with others, like Min3craft.  

3. The way you would play an action game is entirely different from how you would play a trivia game, so certain genres require different gameplay styles.

5 0
3 years ago
Read 2 more answers
Other questions:
  • Which key on a laptop keyboard is often used to help pair a mobile device with another device for communication purposes?
    12·1 answer
  • It is either snoming or below freezing
    10·1 answer
  • David has created a lot of styles and now his Quick Style Gallery contains styles he no longer uses.
    14·2 answers
  • Ricardo twists his ankle at work but does not immediately realize that he is injured because his ankle is not sore or swollen, a
    5·1 answer
  • What does a break statement do
    6·1 answer
  • What are the functions of the windows button, Task View and Search Box? give me short answer
    15·1 answer
  • Which similar computer network components connect multiple devices?
    7·1 answer
  • Helppppppppppp please
    5·2 answers
  • Gabby is creating a game in which users must create shapes before the clock runs out. Which Python module should Gabby use to cr
    15·2 answers
  • What plugs into this?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!