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 trialmellowmushroom
9,250 PointsQuestion about implementing function word_count
Im not sure why my code is not being accepted. This is the result for when i pass the example parameter into the function:
word_count("I do not like it Sam I Am")
{'i': 2, 'do': 1, 'not': 1, 'like': 1, 'it': 1, 'sam': 1, 'am': 1
# 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 = string.lower()
string = string.split(' ')
dictionary = {}
for word in string:
x = string.count(word)
dictionary.update({word: x})
return dictionary
2 Answers
Stuart Wright
41,120 PointsThe problem is that you need to split on all whitespace rather than simply ' ', as there are different types of whitespace characters. So just use .split() without any argument, since all whitespace characters is the default.
It's picky for sure, but it's what you need to do to pass the challenge.
mellowmushroom
9,250 PointsThanks guys!
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsChris Jones
Java Web Development Techdegree Graduate 23,933 PointsThat's weird. I tried something similar and it worked in the Python shell, but didn't work in the quiz. Maybe try contacting Support? I started at Treehouse with Python and I think I remember the quiz questions being very picky....