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 trial

Python Python Collections (2016, retired 2019) Dictionaries Word Count

I 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")

wordcount.py
# 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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles:

Yeap, i forgot to return the result, thank you ^_^

nakalkucing
nakalkucing
12,964 Points

Hey 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

I think it's clear thank's a lot.