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 trialMartin Valov
Courses Plus Student 208 PointsWhat's worng with this code
Simply the code splits the given text into separate words and returns dictionary with the word as the keys and the value of how many times this word is in the list of the words/text.
# 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):
text_arr = text.split(" ")
counted_words = {}
for word in text_arr:
counted_words[word.lower()] = text_arr.count(word)
return counted_words
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHi Martin,
You've pretty much got it, with just one small thing. If you submit the code above, you get the Bummer message "Hmm, didn't get the expected output. Be sure you're lowercasing the string and splitting on all whitespace!"
. The hint is here and has to do with Whitespace.
The challenge is wanting you to split on all whitespace, but you are splitting on only spaces. The split
method can take a parameter on what to split. split(" ")
splits on spaces. If you don't pass any arguments to the method, it will split on all whitespace.
Just fix up that small thing and the rest is good to go!
Nice work. :)
Martin Valov
Courses Plus Student 208 PointsMartin Valov
Courses Plus Student 208 PointsThank you lady !