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
The new software organization requires a new point of sale and stock control system for their many stores throughout Pakistan to
FrozenT [24]

Answer:

hdyfhwjhsucndiskfbvienucuit

7 0
3 years ago
A Java main method uses the parameter (String[ ] variable) so that a user can run the program and supply "command-line" paramete
xxTIMURxx [149]

Answer:

True

Explanation:

Java and some other object oriented programs makes use of the command line arguments. This enables one to pass additional information to a program when it is run. whatever information that is passed to the program at the command line argument will accompany the program when is it run and java stores this information as an array of strings.

4 0
3 years ago
Help me. its due tonight
Novosadov [1.4K]
d- enjoy
b- national service !
5 0
3 years ago
One of the many roles of the security compliance committee is to focus on controls that are widely used across a large populatio
asambeis [7]
ghffyhhuuhhhvccfghhnnnjki
3 0
2 years ago
Look at the four schematic symbols shown in the figure above. Each of the symbols is labeled with a number. Which of the followi
ladessa [460]
The correct answer for the question that is being presented above is this one: "D. Symbol 1 represents a transistor, symbol 2 represents a diode, symbol 3 represents a resistor, and symbol 4 represents a lightbulb." <span>Each of the symbols is labeled with a number. </span>
6 0
3 years ago
Other questions:
  • Blender questions
    8·2 answers
  • On a piano, each key has a frequency, and each subsequent key (black or white) is a known amount higher. Ex: The A key above mid
    14·1 answer
  • What is the purpose of citations?
    13·1 answer
  • Psychographics may also be called A. personality analytics. B. social group dynamics. C. lifestyle analysis. D. opinion insight.
    6·1 answer
  • Explain Spreadsheet and its Basics
    13·1 answer
  • Why is it so important to have employees who can critically think?
    7·2 answers
  • There are some processes that need to be executed. Amount of a load that process causes on a server that runs it, is being repre
    7·1 answer
  • What is the way to discover requirments for software projects ?
    14·1 answer
  • 4. True or False: In order to use wi-fi signal/network, you have to remain seated in one spot.
    6·1 answer
  • Why is a salt added to a password that is being stored in a database?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!