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

Attila Kószó
PLUS
Attila Kószó
Courses Plus Student 9,312 Points

The output works, but the workspace doesn't accept it.

I've made the code in pycharm and it seemingly works, appereanly I have no idea what's the problem in the workspace. The example output matches with mine.

wordcount.py
# 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):
    result = {}
    string = string.lower()
    list_of_keys = string.split(' ')
    for key in list_of_keys:
        if key in result.keys():
            result[key] += 1
        else:
            result[key] = 1
    return result

1 Answer

Taylor Schimek
Taylor Schimek
19,318 Points

Howdy Attila, You are super close to getting this right. The only thing is you delimiter in the .split() method. You have it set like this: .split(' '). That means that the method is looking for a single white space. If you remove the quotes and make it .split(), then if there happens to be two white spaces together in the string, the split() method will consider them one delimiter.
That should pass the challenge. Hope that helps.