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 trialCraig Brooks
3,278 PointsOutput looks very similar but I get 'Bummer'
I wrote my code in PyCharm (it is pasted at the bottom in comments). But when I bring it into here I can seem to pass it. I even tried using your example at the top for confirmation and it outputs the same (minus order, which shouldn't matter on a dict right?).
Can someone please check my code for what I'm doing wrong? I feel my answer is right but it's kind of hard to continue with a false sense of confidence haha.
Thanks!
# 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):
make_dict = []
make_list = list(string.lower().split(" "))
for word in make_list:
make_dict.append([word, make_list.count(word)])
return dict(make_dict)
# Below is my code from PyCharm
# tester = "I do not like it Sam I Am"
# def word_count(string):
# make_dict = []
# make_list = list(string.lower().split(" "))
# for word in make_list:
# make_dict.append([word, make_list.count(word)])
# print(dict(make_dict))
#
# word_count(tester)
# outputs // {'i': 2, 'do': 1, 'not': 1, 'like': 1, 'it': 1, 'sam': 1, 'am': 1}
1 Answer
Steven Parker
231,236 PointsThe "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
. For more details, see the documentation page on "split".
Craig Brooks
3,278 PointsCraig Brooks
3,278 PointsHoly moly! The most fun part of learning to code is realizing those small nuances that fix it when you sit and try over and over and over...or when Steven comes to the rescue haha. Thank you!
Steven Parker
231,236 PointsSteven Parker
231,236 PointsIt warms my heart to think I might be a "most fun part of learning to code".