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 trialeliamani seushi
5,782 PointsAlright, this one might be a bit challenging but you've been doing great so far, so I'm sure you can manage it.
on my local machine it works ,please check my code to see where i am wrong
def word_count(words):
sentence = words.lower()
listOfStr1 = sentence.split(" ")
listOfStr2 = listOfStr1[:]
listofcnt=[]
for i in listOfStr1:
cnt=0
for x in listOfStr2:
if i == x:
cnt = cnt + 1
listofcnt.append(cnt)
zipbObj = zip(listOfStr1, listofcnt)
dictOfWords = dict(zipbObj)
return dictOfWords
output = word_count("I do not like it Sam I Am")
print(output)
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, eliamani seushi ! You're doing terrific! The problem here is partially due to your data set that you're checking. It will pass with the test data, but doesn't pass in all cases. This is because the challenge asks you to split on all whitespace. The only whitespace your test data contains is spaces. But newline characters and tabs are also whitespace and clearly the text Treehouse is testing contains one or both of those.
Where you have:
# this splits on spaces only
.split(" ")
That should be:
# this splits on ALL whitespace
.split()
Simply removing the " " from the split method will tell it to split on all whitespace instead of only spaces.
Hope this helps!