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 trial
James Weis
19,328 PointsCode Challenge Word Count will not pass with correct answer from IDE.
https://teamtreehouse.com/library/python-collections-2/dictionaries/word-count
Here is my solution:
def word_count(string): dict_string = {} list_string = string.lower().split(' ') for i in list_string: count = list_string.count(i) dict_string[i] = count return dict_string
This works as the code challenges explain but swill not pass! Very frustrating. Please point out anything I have done wrong. This works with any string I throw at it in my IDE.
2 Answers
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 PointsSplit with no arguments will split on white spaces, 1 or more. Your split(' ') limits to splitting on single white spaces.
def word_count(string):
dict_string = {}
list_string = string.lower().split()
for i in list_string:
count = list_string.count(i)
dict_string[i] = count
return dict_string
James Weis
19,328 PointsThank you!