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 trialAkshaan Mazumdar
3,787 PointsNOT WORKING
IT says didn't get expected output need to lowercase and split at whitespace.
I ran the same code in my editor it worked properly.
# 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):
x=0
dctn={}
y=(string.lower()).split(" ")
for letter in y:
x=0
dctn.update({letter:0})
for checker in y:
if letter == checker:
x+=1
dctn.update({letter:x})
return dctn
Abigairl N Chigwededza
7,976 Pointsyea we need to see the question first
Akshaan Mazumdar
3,787 PointsReceive a string . Return a dictionary with all the words in lower case along with the number of times each word occurs in the string(see comments in code)
Jennifer Nordell
Treehouse TeacherChristabelle Kamhere and Abigairl N Chigwededza, the challenge is linked at the top right of this question under the "View Challenge" button. Thanks for helping out in the Community!
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! I received your request for assistance, Akshaan Mazumdar and you're super close here. Part of the problem here is the data you're testing. The challenge asks you to split on all whitespace, but currently, you're only splitting on spaces. It should also split on whitespace such as tabs and newline characters and I'm guessing your test data didn't include any of those.
We split on spaces with this:
split(" ")
But we split on all whitespace with this:
split()
Simply removing the quotations and blank space from within the split
function causes this to pass! Excellent work!
Akshaan Mazumdar
3,787 PointsThank You !!! this is valuable information :)
Christabelle Kamhere
5,888 PointsChristabelle Kamhere
5,888 PointsCan I have the question please