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 trialAdam Stefański
14,255 PointsPossibly a bug in Python Collections wordcount challenge.
It says it doesn't return what it's suppose to, but I checked in the Workspaces and it does return exactly that.
# 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(x):
y=x.lower()
z=y.split(" ")
dic={}
for word in z:
if word not in dic:
dic[word]=1
else:
dic[word]+=1
return dic
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsYou are very close! Your code is splitting on a literal space, whereas the challenge checker may be testing using a string with Tabs and spaces mixed. It is best to split on Whitespace. That is, use split()
with no arguments.
Post back if you have more questions. Good Luck!!
Adam Stefański
14,255 PointsAdam Stefański
14,255 PointsThanks Chris! It was driving me crazy. I'm sure going to remember that "Tabs and spaces" thing for future challenges.