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!

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

kelly fink
kelly fink
4,434 Points

What is wrong with my code?

I have been staring at my code for a long time but can't really understand what is wrong with it. I

know that I didn't make any use of the packing method(**). Not sure how to incorporate it into my code. Thank for the help...!

# 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(string.lower()):
    for i in word_count:
        key = i
        value = string.count(i)
        dict = {}
        return dict

1 Answer

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

Dear Kelly, I don't know where to start, First of all you loop trough the method name and not the acctual string. You should use the string, but before that you have to split the string at the white spaces

string.lower().split(' ')

which creates a list and from that list you loop trough. After this u use 'dict' as variable name, dict is already a bultin, So in your code dict=dict Like this is ok:

name = {}
name = dict()

Don't get disappointed because you're doing great. I hope i was for your help if you have any questions please don't hesitate to ask. Happy coding