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 trialStephen Falck
7,558 Pointsmy code works in atom but it keeps saying the output is incorrect on the test
ive tried it repeatedly on atom and the result is correct but here it says: Bummer: Hmm, didn't get the expected output. Be sure you're lowercasing the string and splitting on all whitespace!
# 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):
dict = {}
split_string = (string.lower()).split(" ")
for word in split_string:
counter = split_string.count(word)
dict[word] = counter
return dict
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Stephen Falck ! You're doing terrific and you are really close here! I know that when you put in the test data, it looks like you're getting back the correct thing. And that's because you are... for that data. However, the challenge asks you to split on all whitespace. This includes things like tabs and newline characters. But that test data doesn't contain either one of those.
Currently, you are only splitting on spaces, and not other whitespace characters.
This splits on spaces:
split(" ")
But this splits on all whitespace:
split()
Simply removing the argument " "
from your split
function causes this to pass.
Hope this helps!
Stephen Falck
7,558 Pointsthank you!