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 trialcharlesmonaghan
742 PointsI believe I did this right, but I'm not sure why it's not working?
I'm pretty sure I got everything right. But it just returns the error "Bummer! Try again!".
# 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("this is a string"):
return {'this': 1, 'is': 1, 'a': 1, 'string': 1}
2 Answers
Logan R
22,989 PointsI think you're reading the comments wrong. It's saying it will run your code with those parameters.
# The function you write
def word_count(words_as_string):
# Make a new dictionary for words and their count.
word_dict = {}
# Sum words
# ...
return word_dict
# --------------------------
# You "can't see" this code, but this is how they will call your function
word_counts = word_count("I do not like it Sam I Am")
# Expected dictionary back:
# >>> print (word_counts)
# {'i': 2, 'do': 1, 'it': 1, 'sam': 1, 'like': 1, 'not': 1, 'am': 1}
Hopefully, this helps clear up question!
Christian Lamoureux
Full Stack JavaScript Techdegree Student 22,669 PointsI also am struggling with this one here's what I have so far def word_count(value): the_dictionary = {} value = value.lower() my_list = [''.split(value)] word_list = [] for word in my_list: word_list.append(word) if word == word in word_list: word = str(word) number = [] number.append(word) length = len(number) the_dictionary.update({word: length})
else:
the_dictionary.update({word: 1})
continue
return the_dictionary