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 trialGenius Chamisa
6,620 Pointsword count challenge
where am i going wrong
# 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(string):
string="team treehouse is here"
dictionary={}
dicti=string.lower().split()
for items in dicti:
value=dicti.count(items)
dictionary[items]=value
return dictionary
1 Answer
Robert Stewart
11,921 PointsWell, the one thing I notice is that you're immediately overriding whatever value is passed through as string.
# 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(string): #<= String is passed in here.
string="team treehouse is here" #<= You override it here.
dictionary={}
dicti=string.lower().split()
for items in dicti:
value=dicti.count(items)
dictionary[items]=value
return dictionary
Whatever is calling the code is expecting the answer to be based on the string it passed to the function in the first place. You're returning a completely different result.