Computers and Technology

A common use-case for dictionaries is to store word counts. Let's modify our program below to store the count for each unique word. 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

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 24.06.2019 03:00, greenhappypiggies
Using a conditional expression, write a statement that increments numusers if updatedirection is 1, otherwise decrements numusers. ex: if numusers is 8 and updatedirection is 1, numusers becomes 9; if updatedirection is 0, numusers becomes 7.
Answers: 1
image
Computers and Technology, 24.06.2019 07:40, daebreonnakelly
What type of multimedia are live news feeds? live news feeds are examples of multimedia.
Answers: 2
image
Computers and Technology, 25.06.2019 01:30, parislover2000
What controls can be found on the file tab of microsoft word
Answers: 1
image
Computers and Technology, 25.06.2019 08:00, brandiewilliams12567
Astrategy for speeding up hard drive performance is
Answers: 2
Do you know the correct answer?
A common use-case for dictionaries is to store word counts. Let's modify our program below to store...

Questions in other subjects:

Konu
Mathematics, 03.11.2020 05:00
Konu
English, 03.11.2020 05:00