subject

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

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:30
Communication is the exchange of information. true false
Answers: 2
question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
question
Computers and Technology, 24.06.2019 06:30
Some peer-to-peer networks have a server and some don't. true false
Answers: 2
question
Computers and Technology, 24.06.2019 09:30
What is the definition of digital literacy?
Answers: 1
You know the right answer?
A common use-case for dictionaries is to store word counts. Let's modify our program below to store...
Questions
question
Mathematics, 02.08.2019 08:20
Questions on the website: 13722360