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

Adam Stefański
Adam Stefański
14,255 Points

Possibly a bug in Python Collections wordcount challenge.

It says it doesn't return what it's suppose to, but I checked in the Workspaces and it does return exactly that.

# 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(x):
    z=y.split(" ")
    for word in z:
        if word not in dic:
    return dic

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,389 Points

You are very close! Your code is splitting on a literal space, whereas the challenge checker may be testing using a string with Tabs and spaces mixed. It is best to split on Whitespace. That is, use split() with no arguments.

Post back if you have more questions. Good Luck!!

Adam Stefański
Adam Stefański
14,255 Points

Thanks Chris! It was driving me crazy. I'm sure going to remember that "Tabs and spaces" thing for future challenges.