Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.