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

Why I can't pass the challenge ?

I think that my code is right.

def word_count(sArg):
    dic = {}
    for char in sArg.lower().split(" "):
        if char  in dic.keys():
            dic[char] += 1
        elif char != " ":
            dic[char] = 1
    return dic

But if I check my work I get this massege: " Bummer! Hmm, didn't get the expected output. Be sure you're lowercasing the string and splitting on all whitespace!"

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You haven't linked the challenge, so I can't exactly test it, but I do see something that's incorrect. To be clear, it won't give an error, but it's not exactly what they asked for. The challenge asks you to split on all whitespace. But currently you're only splitting on spaces. This will mean that it will not split on tabs and newlines which are also whitespace.

To split on all whitespace, use the split without any arguments.

Try this line and see if it lets you pass:

for char in sArg.lower().split():

If you're still stuck let me know, and include a link to the challenge, please! :sparkles:

I did pass. Thank you.