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 trialMOUSLIM BOUABDALLAH
Courses Plus Student 17,430 PointsI think i find the solution but the Try again! still there!!
def word_count(phrase): phrase = phrase.lower() b = {} for word in phrase.split(): if word in b: b[word] += 1 else: b[word] = 1 print(b)
word_count("I do not like it Sam I Am")
# 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(phrase):
phrase = phrase.lower()
d = {}
for word in phrase.split():
if word in d:
d[word] += 1
else:
d[word] = 1
print(d)
word_count("I do not like it Sam I Am")
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! You're 99% of the way there and doing terrific! My guess is here that you are printing your results to test them, which is great outside of the challenge. However, the challenge asks you to return
the results... not print them. Also, note that you will not need to call the function yourself. Treehouse will be doing that for you.
I feel like you can get it with this teensy hint, but let me know if you're still stuck!
nakalkucing
12,964 PointsHey Mouslim! You've got your code right until you get to the place where you're supposed to return it. You have it set to print. :) Was that clear? Let me know if you need more help. :)
Best,
Nakal
MOUSLIM BOUABDALLAH
Courses Plus Student 17,430 PointsI think it's clear thank's a lot.
nakalkucing
12,964 PointsWelcome. :)
MOUSLIM BOUABDALLAH
Courses Plus Student 17,430 PointsMOUSLIM BOUABDALLAH
Courses Plus Student 17,430 PointsYeap, i forgot to return the result, thank you ^_^