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
Illusion [34]
2 years ago
10

Write a Python program called wdcount.py which uses a dictionary to count the number of occurrences of each word (ignoring case)

in a pure text file encoding UTF-8. Note that the input text file name is given from the command line. To make it simple, you may assume that the file does not contain any punctuation characters. Your program should print each word along with its number of occurrences in descending order. That is the most frequent word should be printed first.
Computers and Technology
1 answer:
Art [367]2 years ago
5 0

The program is an illustration of loops.

<h3>What are loops?</h3>

Loops are program statements used to perform repetition

<h3>The wordcount.py program</h3>

The program written in Python, where comments are used to explain each line is as follows

# This opens the file in read mode

text = open("myFile.txt", "r")

# This creates an empty dictionary

d = dict()

#This iterates through the text

for line in text:

# This splits the line into words, after removing leading & trailing spaces, and newline characters

words = line.strip().lower().split(" ")

# This iterates through all the words

for word in words:

 # The following if condition counts the occurrence of each word

 if word in d:

  d[word] = d[word] + 1

 else:

  d[word] = 1

#This prints the words and their frequencies, in descending order

for w in sorted(d, key=d.get, reverse=True):

   print(w, d[w])

Read more about loops at:

brainly.com/question/16397886

You might be interested in
A word that has a specific, predefined meaning in a programming language is called
vampirchik [111]
<span>The correct answer is


A keyword</span>
5 0
3 years ago
I want to sign up for brainly but it won't let me. It keeps saying "we can complete your registration at this time".
vekshin1
Try reinstalling the app or check if your wifi connection is good, if everything’s good but the app still doesn’t work then just use the website
5 0
3 years ago
People who work the total hours for which they get paid have
Troyanec [42]
Perfect attendance and a salary
7 0
3 years ago
Read 2 more answers
&gt;&gt;&gt; import math &gt;&gt;&gt; print(math.Pi) 3.141592653589793 &gt;&gt;&gt; def print_volume(): print ("What is the radi
kvasek [131]
I have no clue what this is asking...
8 0
3 years ago
What do you understand by storage devices ? Name any two storage devices.​
MatroZZZ [7]

Answer:

Types of storage devices

Primary Storage: Random Access Memory (RAM) Random Access Memory, or RAM, is the primary storage of a computer. ...

Secondary Storage: Hard Disk Drives (HDD) & Solid-State Drives (SSD) ...

Hard Disk Drives (HDD) ...

Solid-State Drives (SSD) ...

External HDDs and SSDs. ...

Flash memory devices. ...

Optical Storage Devices. ...

Floppy Disks.

6 0
3 years ago
Read 2 more answers
Other questions:
  • There are 55 registers, and total 60 instructions available in a general-purpose computer. The computer allows only 2-address in
    6·1 answer
  • What does the Finder do?
    7·1 answer
  • When your friend DaJuan turns on his computer, he hears four beeps. The computer won’t fully boot. DaJuan has a Dell computer wi
    7·1 answer
  • Which option on the Format tab is used to modify particular portions of the chart?
    12·1 answer
  • MacBook Pro (2019) at 93% max capacity battery rating after 100 charge cycles. Is this normal? Used coconut battery to check thi
    10·2 answers
  • List any two programs that are required to play multimedia products
    8·1 answer
  • It is usually simple to delete old posts and online conversations if they make you look bad.
    5·1 answer
  • Question 8 (True/False Worth 3 points)
    15·1 answer
  • . Write a function sumLastPart which, only using list library functions (no list comprehension), returns the sum of the last n n
    6·1 answer
  • Non linear editing can cause _____ where edit and re-edit and re-edit again can cause video to be less true than the original ma
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!