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 trialMduduzi Frederick Dube
8,886 PointsWhere is 'word count'?, how am I not defining the function correctly such that it fails to be read as a funtion.
Where am I missing it?
def word_count(string):
value = string.lower().split(' ')
for word in value:
my_dict[word] = value.count(word)
return my_dict
2 Answers
Steven Parker
231,275 PointsIt looks like you forgot to initialize my_dict before assigning to it.
Initialization to an empty set will identify it as a dictionary and not an array.
Brian Jensen
Treehouse StaffYou are so very close!
def word_count(string):
my_dict = {}
value = string.lower().split(' ')
for word in value:
my_dict[word] = value.count(word)
return my_dict
Mduduzi Frederick Dube
8,886 PointsMduduzi Frederick Dube
8,886 PointsThanks a lot.