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
Max Gollinger
7,533 PointsIn workspaces my code has the right output but in the code challenge it says "didnt get the expected output" ...
# 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.
string = "I do not like it Sam I Am"
def word_count(string):
my_dict = {}
string = string.lower().split(" ")
for each in string:
if each in my_dict.keys():
my_dict[each] = my_dict[each] + 1
else:
my_dict[each] = 1
return my_dict
If i try this in workspaces, the output is like the example above... i honestly have no idea where i got it wrong
1 Answer
Steven Parker
243,656 PointsThe challenge may (will!) test your program using data other than the example. You didn't link to the challenge, but if I remember it may have said something about splitting on any whitespace. But I see you passed a space as an argument to "split" which causes it to split (only) on individual spaces.
Try leaving the argument to "split" empty and see if that helps.
If that's not it, please provide a link to the challenge page.
Max Gollinger
7,533 PointsMax Gollinger
7,533 PointsThank you! That was it :)