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 trialitamar dahan
1,297 PointsWord Count challenge won't pass even though my code works
Hey
Using my testing in my local environment, i see that i get the expected results. even when using the example in the comments, i get the answer as the example.
But i still get "Bummer!" when i press check =( Any ideas?
# 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 (s):
s = s.lower()
lst = s.split(' ')
diction = {}
for item in lst:
diction[item] = 0
for key in diction.keys():
for item in lst:
if item == key:
diction[key] += 1
print(diction)
3 Answers
Bapi Roy
14,237 PointsIn place of print the result. You need to return the result.
reanimator313
6,005 PointsWhat Bapi Roy said, and uses .split () without any argument, this way it removes all spaces ('TAB' ...)
Barbara Bai
8,295 PointsI dunno how sensitive the language you are using is to spaces, but I see a space between word_count and (s), and maybe you need to get rid of that space.
itamar dahan
1,297 Pointsitamar dahan
1,297 Pointslol thanks