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 trialAf Mondal
2,437 Pointsnot getting the right count of words
I am confused. It seems to me that I am doing right but challenge is saying that count of word is not same for some words. What is wrong....
def word_count(string):
my_list = {}
a = string.split(" ")
for word in a:
value = len(word)
my_list[word] = value
return my_list
1 Answer
Andy Swinford
8,152 PointsI think this is the one where it wants you to count how many times a word is used and not how many characters each word has. See my answer below.
def word_count(string):
my_list = {}
a = string.split()
for word in a:
if word not in my_list:
my_list[word] = 1
else:
my_list[word] += 1
return my_list
Af Mondal
2,437 PointsAf Mondal
2,437 PointsThanks andy it worked.