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

Wayne Leyden
Wayne Leyden
4,995 Points

"Where's 'word_count()'?"

This has happened 4 or 5 times usually i just completely rewrite the whole thing and it works it didn't this time. Please point out where i am making the mistake.

def word_count(the_string):
  dictt = {}
  word_list = List(the_string.lower)

  for word in word_list:
    if word in dictt:
      dictt[word] += 1 
    else:
      dictt[word] = 1
  return dictt

3 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Likely the List mistake caused the function to be uncallable, so the test runner couldn't find it.

Joseph Kato
Joseph Kato
35,340 Points

As Chris pointed out, list is lower-case. In addition, I think you're meaning to call the .lower method on the_string, which would look like this:

word_list = list(the_string.lower())

However, with that said, I don't think think this is actually what you want to do. For example:

>>> the_string = "I am a string"
>>> word_list = list(the_string.lower())
>>> word_list
['i', ' ', 'a', 'm', ' ', 'a', ' ', 's', 't', 'r', 'i', 'n', 'g']

As you can see, this is not a list of words. Have you looked into the .split string method?

Chris Shaw
Chris Shaw
26,676 Points

Hi Wayne,

The only issue I see is you have the L list upper-case instead of lower-case.

word_list = list(the_string.lower)