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
Which of the following is a public location that sells Internet access? Internet café Extranet Intranet LogMeIn,
Goshia [24]

Answer:A) Internet cafe

Explanation: Internet cafe is the place that provides the internet service to the public and helps them to access the internet .These cafes can be used by the public who are travelers, people who don't have access at home etc.This internet cafe works on the basis of the hourly rate that it takes from the public.

Rest of the options are incorrect  as intranet and extranet are types of network and LogMeIn is a desktop service .thus, the correct option is option(A).

8 0
3 years ago
Unlike a virtual image, a real image
IRINA_888 [86]
C.cannot be viewed on a screen
4 0
3 years ago
Name the character encoding standard that enables up to 128 different commonly used characters,
Lelechka [254]

Answer:

ASCII character set.

Explanation:

ASCII is an acronym for American Standard Code for Information Interchange and it was developed from a telegraph code. It is typically a character encoding standard that comprises of seven-bit (7-bit) set of codes.

ASCII character set is the character encoding standard that enables up to 128 different commonly used characters, numbers and symbols to be used in electronic communication systems. The ASCII character set is only used for encoding English language and it comprises of both the lower case and upper case letters of the 26 alphabets, number 0 to 9 and symbols.

8 0
3 years ago
Cathy designed a website for a cereal brand. When users view the website, their eyes first fall on the brand name, then they vie
PSYCHO15rus [73]

Answer:

dominance

Explanation:

i just took it and got it right

4 0
3 years ago
A cathedral hull allows the boat to do what
Hoochie [10]
It allows power boats to have stability while cruising. The cathedral hull  is like a trimaran in terehat it has one main  and two side hulls stuck together so that has a somewhat square to rectangular shape and therefore exhibits greater stability than a single hulled boat. It became more popular with the advent of fibreglass boats in the 1960's and '70s.
5 0
3 years ago
Other questions:
  • How to eject a flash drive from chromebook?
    6·1 answer
  • You can install several printers on your machine, but at least one must be the _______ printer.
    6·1 answer
  • Naruto Uzumaki who likes naruto ??? who waches it??
    14·2 answers
  • The number of bits that can be transferred per second over a given transmission medium.
    6·1 answer
  • Ethical design refers to...
    13·1 answer
  • What is the way to discover requirments for software projects ?
    14·1 answer
  • PLEASE HELP I WILL GIVE BRAINLIEST!!!!
    7·2 answers
  • Anyone trying to play fortnite ? im bored lol
    6·2 answers
  • Please please help I don’t understand this
    6·1 answer
  • The…..executed simple
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!