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
As we learned in this lesson, a byte is about the same amount of memory as a character, such as the letter 't'. There are approx
Papessa [141]

Answer:

Give an example of a special purpose computer that you are familiar with and briefly describe its hardware and its software.

One example of a special purpose computer is a microwave because the programs on a microwave (like the "Popcorn" program) can't be changed. The hardware of a microwave include its buttons, the door, the light bulb, the transformer, the waveguide, the magnetron, and the control circuit. The software of a microwave is all of the programs that make the microwave run. These include the "Popcorn" program that is supposed to perfectly make your popcorn, the "Sensor" program that senses for a certain type of food/drink and adjusts the temperature accordingly, or a "Defrost" program which can be used to defrost meat.

   2. Explain in your own words the difference between running your app by "Connecting to the Companion" and running your app by "Packaging" it.

When running the app by "Connecting to the Companion", the MIT companion app transfers the software (blocks) to the phone and then interprets them for the Android operating system. The Android OS takes the software and interprets it for the phone's processor so the app can run. Because of the way "Connecting to the Companion" works, the code can be re-interpreted every time a change is made. This process is known as interpretation because the code is constantly being re-interpreted.

When running the app by "Packaging" it, a program changes the software (blocks) on the computer into binary code and then packages it in an .apk file. Using a barcode scanner or another piece of software, the .apk file can be loaded onto the phone so the Android OS can interpret the code for the phone's processor. This process is called compilation since all of the source code is changed into binary.

     3. As we learned in this lesson, a byte is about the same amount of memory as a character, such as the letter 't'. There are approximately 7 million characters in all of the Harry Potter novels combined. How many bytes of memory would all of the Harry Potter novels take up? How many copies of the Harry Potter novels would fit on a 7 Gigabyte flash drive. (Remember 1 Gigabyte is 1 billion bytes.)

The Harry Potter novels would take up approximately 7 million bytes. This means that 1,000 copies of the Harry Potter novels could fit on a 7 Gigabyte flash drive!

5 0
4 years ago
Please I need all the help I can get
Butoxors [25]
Number 2 is c hope I help
5 0
3 years ago
In a(n) ____________________ device, the movement of electrons performs essentially the same functions as gears and wheels in me
lana66690 [7]

Answer:

Electronic computing.

Explanation:

8 0
2 years ago
If you delete a conversation many times with someone like this, will you stop receiving messages from them?
GREYUIT [131]

Answer: No

Explanation:

4 0
3 years ago
The process of finding the largest and smallest numbers is used frequently in computer applications. Write a C++ program that us
WINSTONCH [101]

Answer:

The program to this question can be given as:

Program:

#include<iostream>  //header file

using namespace std;

int main()    //main method

{

int x[10],i,largest = 0,second_largest=0,n;  //variable

cout << "Enter Number of elements :";  //message

cin>>n;

cout << "Insert array elements :";  //message

for(i=0;i<n;i++)  //insert elements in array

{

cin >>x[i];

}

//Finding Largest element  

for(i=0;i<n;i++)

{

if (x[i]>largest)

{

largest = x[i];

}

}

//finding second largset element

for(i=0;i<n;i++)

{

if (x[i]>second_largest)

{

   if(x[i]==largest)

   {

   continue;   //Ignoring largest in order to get second largest

   }

   second_largest=x[i];

}

}

//print value

cout <<"Largest Number:"<<largest<<endl;

cout <<"Second Largest Number:"<<second_largest;

return 0;

}

Output:

Enter Number of elements :5

Insert array elements :33

45

75

87

23

Largest Number:87

Second Largest Number:75

Explanation:

In the above program firstly we define the header file then we define the main method in the main method we define the array and other variables. We first input the number for the size of the array. Then we insert array elements after inserting array elements we search the largest number and the second largest number in the array. To search the largest number in the array we use the loop. To search the first largest number we define a condition that array is greater than the largest number and store the value into the largest variable. Then we check the second largest number in the array for this we use two conditions that are array is greater than the second largest number in this we use another condition that is array is equal to the largest number. If the inner condition is true then it will move forward and end of an inner condition. In the outer condition, the value will be stored on the second_largest variable all the conditions will be done inner the loop. At the last we print values.

3 0
3 years ago
Other questions:
  • If you quote an author from a website in a paper, it will be important to create a _____ in your writing to give them credit for
    7·2 answers
  • If an app needs to perform a derived-class-specific operation on a derived class object reference by a base class variable, the
    9·1 answer
  • Emilio is reviewing the data he collected from historical records about immigration in the united states. He decides to create a
    5·1 answer
  • Suppose the work required to stretch a spring from 1.1m beyond its natural length to a meters beyond its natural length is 5 J,
    14·1 answer
  • Read the Security Guide about From Anthem to Anathema on pages 238-239 of the textbook. Then answer the following questions in t
    14·1 answer
  • NMCI is the name used for a large-scale effort to link Navy and Marine Corps computer systems on bases, boats, and in offices ar
    15·1 answer
  • I need trash talk for a comeback:
    11·2 answers
  • How does an Ac Machine work
    14·1 answer
  • What's the best thing that's happened to you during quarantine?
    10·2 answers
  • True/False: Functions are ideal for use in menu-drive programs. When a user selects a menu item, the program can call an appropr
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!