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
alexdok [17]
3 years ago
9

A common use-case for dictionaries is to store word counts. Let's modify our program below to store the count for each unique wo

rd. Let's name the dictionary word_counts. This means you need to initialize the count value to 1 for a particular word if you see it for the first time (i.e., it's not already in word_counts) and update the count (by adding 1 to it) if the word is already present in word_counts.
# Code here

# open the file
f = open("words.txt")
# read the text and store in variable
text = ________
# initialize a dictionary
word_counts = ________
# populate the dictionary with words and their associated counts in the text
# for each word in the text (split by spaces)
# if we haven't seen it
# initialize it in the dictionary to a value of 1
# otherwise
# update the count by 1

# print out the word counts
Computers and Technology
1 answer:
baherus [9]3 years ago
8 0

Answer:

word_count={}

for i in text.split:

        if i in word_count:

                word_count[i]+=1

         else:

                 word_count[i]=1

print word_count

You might be interested in
The ___________ method returns the length of an array.
MaRussiya [10]

Answer:

A. Append

Explanation:

4 0
2 years ago
Read 2 more answers
Some files appear dimmed in one of the default folders on your computer. What would be the best course of action? A. Leave the f
Zielflug [23.3K]
If some files appear dimmed in one of the default folders on your computer, the best course of action would be to A. leave the files as they are.
These files are probably either hidden or system files, which are never meant to be deleted or moved.
8 0
3 years ago
What is an IF statement used for?
kiruha [24]

The IF statement is a decision-making statement that guides a program to make decisions based on specified criteria. The IF statement executes one set of code if a specified condition is met (TRUE) or another set of code evaluates to FALSE.

8 0
2 years ago
your browsing the internet and realize your browser is not responding. which of the following will allow you to immediately exit
Mandarinka [93]

Answer:

Task Manager is the answer

8 0
3 years ago
Meaning of fetch cycle​
kherson [118]

Answer:

The instruction cycle (also known as the fetch–decode–execute cycle, or simply the fetch-execute cycle) is the cycle that the central processing unit (CPU) follows from boot-up until the computer has shut down in order to process instructions.

Explanation:

7 0
2 years ago
Other questions:
  • Which sentence best describes an activity stream?
    10·2 answers
  • This toolbar has icons representing the application's basic operations such as Save and Copy. Drawing Formatting Standard Task
    11·2 answers
  • Spreadsheet software creates a ____, composed of a grid of columns and rows
    5·1 answer
  • Standards for all managers ethical responsibilities are covered in a company's
    7·2 answers
  • Expectation on Information Technology Fundamental​
    12·1 answer
  • How do I go to files in Brainly I need help
    13·1 answer
  • Define a function below, filter_out_strs, which takes a single argument of type list. Complete the function so that it returns a
    10·1 answer
  • Which tab on the Ribbon contains the command to print a publication?
    10·1 answer
  • What information is necessary to review in order to be considered familiar with the Safety Data Sheet (SDS) of a substance
    7·1 answer
  • Have the javascript function CountingMinutes(str) take the str parameter being passed which will be two times (each properly for
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!