Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Michael Davis
PLUS
Michael Davis
Courses Plus Student 12,508 Points

Python Collections Challenge

For the challenge, my code works in Workspace using the given example, however it fails when being submitted.

The error message I'm getting is:

Bummer! Hmm, didn't get the expected output. Be sure you're lowercasing the string and splitting on all whitespace!

It doesn't give me any information that would allow me to debug my work, so I have nothing to go on here.

Any help is appreciated.

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(msg):
    words = msg.lower()
    words.split()
    wordDict = {}

    for s in words:
        try:
            wordDict[s] = wordDict[s] + 1
        except KeyError:
            wordDict[s] = 1

    return wordDict 

2 Answers

Michael Davis
PLUS
Michael Davis
Courses Plus Student 12,508 Points

Solved it, I was missing a variable assignment. One of the mutations to the string I assumed was a destructive mutation (modified the string itself), when it actually made a copy that I needed to capture.

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,258 Points

it tells you to split on all whitespace. you are only splitting on the space character. other whitespace characters include newlines and tabs among others. split on () instead of (" ").

Michael Davis
Michael Davis
Courses Plus Student 12,508 Points

I made the change from .split(" ") to .split() and received the same error.