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

Fernando Santos
Fernando Santos
11,267 Points

Code running on workspace but not on browser

The code is running as required on my workspace, but they don't accept it in the code challenge. I can't realize what's wrong.

wordcount.py
def word_count(string):
    lista = string.lower().split(" ")
    lista2 = lista.copy()
    dicionario = {}
    for word in lista:
        count = 0
        while word in lista2:
            lista2.remove(word)
            count += 1
            dicionario[word] = count
    return dicionario

1 Answer

Steven Parker
Steven Parker
231,275 Points

You're really close! And there's a clue in the error message you get: "Bummer: ... Be sure you're lowercasing the string and splitting on all whitespace!"

To split on "all whitespace" the argument to "split" should be left empty (or set to None). Providing a space argument causes it to split only on individual space characters. See the Python documentation for "split" for more details.