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 trialAnton Kamynin
20,412 PointsCan`t pass the challenge with working solution
Hi! Have some issues with this python challenge. I`ve tested this code on my local python env and everything works fine. But I get an error on submitting this script at treehouse, and have no idea where i can make a mistake. Please, help!)
def word_count(string):
result = {}
string = string.lower().split(" ")
for word in string:
if word in result:
result[word] += 1
else:
result[word] = 1
return result
word_count("I do not like it Sam I Am or Am I not I")
1 Answer
Steve Hunter
57,712 PointsHi Anton,
The issue here is that you are defining and overriding whitespace. If you use the default whitespace split method, .split()
, rather than split(" ")
, then your code is fine. The first usage splits on any whitespace. Your implementation splits on single spaces only.
I hope that helps,
Steve.
Anton Kamynin
20,412 PointsAnton Kamynin
20,412 PointsGreat! Thanks a LOT, Steve! It works!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsNo problem!