Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.