count_total_words

count_total_words#

Given a dictionary word_freq that maps a word to the frequency count (i.e., number of times the word occurs in a sentence), write a function count_total_words to return the total number of words in the sentence.

For example, if the sentence is “all is well that ends well”, then the dictionary will contain {"all":1, "is":1, "well":2, "that":1, "ends":1}. Your function should count the total number of words in that dictionary (including duplicates). For this example, your function should return 6.

Another example: if the sentence is “I scream you scream we all scream for ice cream”, the word_freq dictionary (i.e., input parameter to the function) will contain {"I":1, "scream":3, "you":1, "we":1, "all":1, "for":1, "ice":1, "cream":1} and your function should return 10.

Sample Input 1:

{"all":1, "is":1, "well":2, "that":1, "ends":1}

Sample Output 1:

6

Sample Input 2:

{"I":1, "scream":3, "you":1, "we":1, "all":1, "for":1, "ice":1, "cream":1}

Sample Output 2:

10