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 trialYaroslav Cheremnykh
17,692 PointsI can't complete wordcount challenge due to the odd bammer.
I tried to launch my code in IDE. All requirements passed. But i still have a bammer error ("Hmm, didn't get the expected output. Be sure you're lowercasing the string and splitting on all whitespace!"). What should i do with my code to move forward in correct way? Thanks.
My code:
# 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(phrase):
word_list = phrase.lower().split(' ')
dictionary = dict.fromkeys(word_list)
keys = dictionary.keys()
for i in keys:
counter = 0
for z in word_list:
if z == i:
counter += 1
else:
continue
dictionary[i] = counter
return dictionary
word_count(phrase='I do not like it Sam I Am')
2 Answers
Steven Parker
231,248 Points Be careful about testing a challenge in an external REPL.
If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.
The challenge said to "Be sure you're ... splitting on all whitespace". But if you pass a space as an argument to split, it will only split on spaces (and on every space). To split on "all whitespace" you leave the argument empty.
Yaroslav Cheremnykh
17,692 PointsSteven Parker, Thanks for your rapid answer. Now all things is clear. I'll keep in mind this feature of split method. My code passed the challenge.
Richard Boothe
25,204 PointsRichard Boothe
25,204 PointsSteven Parker, Good catch. This tripped me up as I come from a JavaScript background where the default isn't on whitespace. I up-voted you and hopefully you get answer credit!
Here's my solution since I'm here:
Steven Parker
231,248 PointsSteven Parker
231,248 PointsIt's always great when I can help more than one student with an answer.