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 trialKonstantin Kovar
16,003 PointsIs this challenge buggy? I have tried it locally and my solution works just fine.
I don't really have anything to add to my question there xD
# 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):
word_list = string.lower().split(' ')
sol = {}
for word in word_list:
if word in sol:
sol[word] += 1
else:
sol[word] = 1
return sol
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey there Konstantin,
You've pretty much right on, except for one thing... what you are splitting on. It isn't really defined in the original instructions, but if you run the code you have now, you get an error saying something about not splitting on "all whitespace." That's the big hint here.
Right now with .split(' ')
you are splitting on whitespace, but only spaces. You'll want to include 'tabs,' 'returns,' etc. To accomplish this, you just leave the params passed into the split method empty.... .split()
.
Keep Coding!
:)
Konstantin Kovar
16,003 PointsAaaaah, yeah, that worked, thanks a million!