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 trialchunjie liu
Python Web Development Techdegree Student 1,815 Pointsword_count I have checked my code in the workspaces and i got the expected output But cannot check it
I still got Unexpected Output when i check it in the units: https://teamtreehouse.com/library/python-collections-2/dictionaries/word-count
# 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(item):
word_list=item.split(" ")
low_word_list=[]
for word in word_list:
low_word=word.lower()
low_word_list.append(low_word)
i=0
word_dict={}
while i<len(low_word_list):
j=1
if low_word_list[i] not in word_dict.keys():
word_dict.update({low_word_list[i]:j})
i+=1
else:
m=word_dict[low_word_list[i]]+1
word_dict.update({low_word_list[i]:m})
i+=1
return word_dict
1 Answer
Steven Parker
231,275 PointsYou're really close, and the "Bummer" message gave you a hint: "Be sure you're lowercasing the string and splitting on all whitespace!".
To split on "all whitespace" the argument to "split" should be left empty or set to None
.
chunjie liu
Python Web Development Techdegree Student 1,815 Pointschunjie liu
Python Web Development Techdegree Student 1,815 PointsOH! I got it! Thank you!!!
Steven Parker
231,275 PointsSteven Parker
231,275 Pointschunjie liu — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!