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

What is wrong with my code?

It seems to be working well in workspaces but I only get "Bummer! Try again!"

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:
    counts = dict()
    words = str.split()

    for word in words:
        new_word = word.lower()
        if new_word in counts:
            counts[new_word] += 1
        else:
            counts[new_word] = 1

    return counts

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're really close here, but you've forgotten to make it so that the function takes an argument. This also means that one of your other lines will need to be adjusted. Treehouse is going to send in a string to test it so it must accept information coming into it.

The declaration of your function should start with:

def word_count(words):

After you change this, you will receive an error about the split. If you modify that line just slightly, your code passes!

I'm going to leave a little debugging to you, but let me know if you're still stuck and I'll be glad to help! :sparkles:

Thanks a lot.

Hi Jennifer,

Can you tell whats wrong with my code?

def packer(**kwargs):
return (kwargs)

def word_count(string): string = string.lower()
list1 = string.split()
for item in list1: newlist.append(item = (newlist.count(item)) packer(",".join(newlist))