Python Python Collections (2016, retired 2019) Dictionaries Word Count

Vladimir Lapcevic
Vladimir Lapcevic
6,363 Points

how to unpack and count data from a sentance?

Please help what should be my next step. Thanks
# E.g. word_count("I do not like it Sam I Am") gets back a dictionary like:
# {'i': 2, 'do': 1, 'it': 1, 'sam': 1, 'like': 1, 'not': 1, 'am': 1}
# Lowercase the string to make it easier.

def word_count(**randomWords):

1 Answer

Oszkár Fehér
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Vladimir. If you use ** in the parameter, then it should be a dictionary the randomWords, but the quiz says

I need you to make a function named word_count. It should accept a single argument which will be a >string<. 
The function needs to return a dictionary.

So far you defined the function, give it a try. I know it can be hard at the beginning, but if you don't try and somebody gives you the answer it will not help. The next step, you should iterate through the string in your function is the randomWords and lowered with .lower(). You need to use a for loop in order to loop through the string. The string is like a list of words. Looping through the string, you can count how many times the words are in that sentence. Give it a try, rewatch the videos if it's necessary, there is no shame in that, myself I do rewatch some videos when it's needed. If you're still stuck we can continue from there.