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 03:10
This program reads a file called 'test.txt'. you are required to write two functions that build a wordlist out of all of the words found in the file and print all of the unique words found in the file. remove punctuations using 'string.punctuation' and 'strip()' before adding words to the wordlist. write a function build_wordlist() that takes a 'file pointer' as an argument and reads the contents, builds the wordlist after removing punctuations, and then returns the wordlist. another function find_unique() will take this wordlist as a parameter and return another wordlist comprising of all unique words found in the wordlist. example: contents of 'test.txt': test file another line in the test file output: ['another', 'file', 'in', 'line', 'test', 'the']
Answers: 1
question
Computers and Technology, 22.06.2019 09:00
Designing a mobile web page is a little different from designing a regular web page. name at least three features that should be considered when designing a website that is mobile phone-friendly, and briefly explain why they are important.
Answers: 1
question
Computers and Technology, 22.06.2019 10:50
Using least squares fitting, you are to fit the data sets to the following models and solve for the parameters ai , where i is the index of the parameter. the input/output data for the systems are linked in the bblearn site. for each of the systems use matlab to plot the supplied data vs. the model fit on one plot. include your code in the solutions. (a) linear fit "lineardata.mat" y=a1x^3 + a2x^2 + a3x + a4 (b) plant fit "plantdata.mat g(s) = a1/(s + a2)
Answers: 1
question
Computers and Technology, 22.06.2019 13:30
Asoftware company hired ray, a college graduate to work in their development team. ray is assigned to work in the coding phase of a project. what happens during the coding phase of a software development project? a. the customer receives a working model of the software. b. developers convert the program design into code. c. developers gather requirements directly from the stakeholders. d. testing teams check the product for quality.
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, 15.04.2020 19:48
question
Mathematics, 15.04.2020 19:48
Questions on the website: 13722363