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 (Retired) Dictionaries Word Count

Keep getting same vague error, can't pass challenge. The code works great in my IDE however... just not on treehouse.

This code "passes" when I run it through Pycharm on my MAC. No matter what I do or try, the code fails in the Treehouse program. The error says it did not receive the correct word count. PyCharm disagrees.... Can some one explain what I am doing wrong?

word_count.py
# E.g. word_count("I am that I am") gets back a dictionary like:
# {'i': 2, 'am': 2, 'that': 1}
# Lowercase the string to make it easier.
# Using .split() on the sentence will give you a list of words.
# In a for loop of that list, you'll have a word that you can
# check for inclusion in the dict (with "if word in dict"-style syntax).
# Or add it to the dict with something like word_dict[word] = 1.

ship_song = "I am that I am"


def word_count(ship_song):
    words_found = {}
    ship_song = ship_song.lower()
    words = ship_song.split(' ')
    for word in words:
        if word in words_found.keys():
            words_found[word] = (int(words_found[word]) + 1)
        else:
            words_found[ word] = "1"
    return words_found

```/Users/splice/miniconda3/bin/python /Users/splice/PycharmProjects/List_Swap/quiz {'that': '1', 'am': 2, 'i': 2}

Process finished with exit code 0```

Here's my output when I run the code through Pycharm. It appears to pass the requirements. Do other people agree? My apologies if I'm going about this all wrong, this is the first example where I'm truly stumped. I appreciate and constructive comments that can be made.

1 Answer

Hey! The problem is that the values are expected to be ints not strings

 # try it without the ""
words_found[ word] = 1

Rock on Jeremiah! I swore I had found a bug in the challenge.... I was too quick to assume. Excellent work man.