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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Travis John Villanueva](https://secure.gravatar.com/avatar/b4f257e6ca56b104da71ffacc81e48c2?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Travis John Villanueva
5,052 Pointsword_count.py
So, i tested in worskpace, and i replicate the example and it returns the same result. I dont know what is wrong as the error message says try again. Can you please shed light?
Thanks!
# 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(text):
dict_text = {}
text_splitted = text.split(" ")
for i in range(len(text_splitted)):
text_splitted[i]=text_splitted[i].lower()
for i in range(len(text_splitted)):
num_ins = 0
for a in range(len(text_splitted)):
if (text_splitted[i] == text_splitted[a]):
num_ins += 1
else:
pass
dict_text[text_splitted[i]]=num_ins
return dict_text
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
231,128 PointsYou're pretty close, but I can see two issues:
First, there's an indentation error on the last two lines. They both need to be indented one more level, otherwise the assignment is outside of the loop and the "return" is completely outside of the function.
Then, when splitting the words, you should split on "all whitespace". To do this, leave the argument to "split" empty. Giving it a space argument causes it to split on individual spaces.
Fix those and you should pass!