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 trialBobby Tagget
16,564 PointsApparently my solution is incorrect
I am not sure what I am doing wrong, I've tested my output through my Mac's terminal and it's showing me exactly what's expected of the challenge.
# 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(some_string):
some_dict = {}
string_split = some_string.split(" ")
for word in string_split:
some_dict[word.lower()] = 0
for word in string_split:
some_dict[word.lower()] = some_dict[word.lower()] + 1
return some_dict
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! You are so close here. If you'll take a good look at the Bummer! message you'll notice that it says you must split on all whitespace. Currently, you're only splitting on spaces. My guess is that your data sets that you tested did not include any tabs or new line characters. Which means that the results will not be what is expected. You are using split(" ")
to split on spaces. To split on all whitespace you can use the split method with no arguments like so: .split()
. This will split the string on all whitespace including tabs and new line characters.
Hope this helps!
Bobby Tagget
16,564 PointsBobby Tagget
16,564 PointsThis helps greatly! Thanks Jennifer