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
Adding Calculator Write a program that simulates an adding machine. Input to the program will be integers, submitted one per lin
Marysya12 [62]

Answer:

This is really hard. I tried doing this problem but of was a real pain. I honestly can't help. I tried. sorry mate.

7 0
3 years ago
Web browsers are used to browse the world wide web.
VikaD [51]
No its actually used for looking up concerns, questions, or rumours
3 0
4 years ago
Read 2 more answers
what is the the process of sending a packet from one host to a selected group of hosts, possibly in different networks?
Burka [1]
I believe it's "multicast"
6 0
3 years ago
Many mobile devices include a mini- ________ port.
nekit [7.7K]
USB Port, otherwise how would you plug it externally?
5 0
3 years ago
Plz help me on this one
abruzzese [7]
I can’t see all the answer choices.
8 0
4 years ago
Read 2 more answers
Other questions:
  • Write a program that estimates the approximate number of times the user’s heart has beat in his/her lifetime using an average he
    12·1 answer
  • Does the steelseries arctis 9x work with a pcie bluetooth card in windows
    13·1 answer
  • How do you take a picture on this app
    10·1 answer
  • Why do computers use zeros and ones? a. because combinations of zeros and ones can represent any numbers and characters b. becau
    6·1 answer
  • What do character formats do for your document's message? A. Set how text aligns within a document B. Provide organization C. Pr
    6·2 answers
  • Do you watch markiplier?
    13·2 answers
  • Programs which were typically reserved for college-level classes such as computer animation and CAD programs are now being appli
    13·1 answer
  • Personal information in the computer can be viewed and stolen
    7·1 answer
  • Cookie Snooping
    14·1 answer
  • Is there a way to delete a question on brainly?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!