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 trialRicardo Rodriguez
9,758 PointsWhat words are supposed to be used for this exercise?
I did my coding and is doing exactly what is expected and I know this because I've tested out of the workroom locally in my own python install and it works! but when I do the exercise the result says:
"Bummer! Some of the words seem to be missing!"
Previously in another exercise where we were supposed to get "kaoa" (letters from oKlAhOmA) code was right but I was just not testing it with the right word so I guess I might be using the wrong string on this exercise too.
Can someone please tell what string should I test the word_count.py code with?
Thank you.
# E.g. word_count("I am that I am") gets back a dictionary like:
# {'i': 2, 'am': 2, 'that': 1}
# Lowercase the string to make it easier.
# Using .split() on the sentence will give you a list of words.
# In a for loop of that list, you'll have a word that you can
# check for inclusion in the dict (with "if word in dict"-style syntax).
# Or add it to the dict with something like word_dict[word] = 1.
def word_count(dale):
dale = "I am that I am"
eldir = {}
vez = 0
palabras = dale.split(' ')
print("Palabras = ", len(palabras))
for palabra in palabras:
if palabra in eldir.keys() :
eldir[palabra] = eldir[palabra] + 1
else:
eldir[palabra] = 1
return(eldir)
cuero = {}
word_count(cuero)
2 Answers
Chris Freeman
Treehouse Moderator 68,454 PointsYou are hard-coding the value of your function argument date
with the string "I am that I am". Remove or comment out that line so the function can be used with other input data.
Two issues in your test code, First,word_count
argument is a string not a dict. Second, since cuero
is empty, There is nothing for the function to process:
cuero = {}
word_count(cuero)
Change this lines to:
cuero = "This test is a test string that is"
word_count(cuero)
dale = "I am that I am"
word_count(dale)
Ricardo Rodriguez
9,758 Points@chrisfreeman3 @chris freeman
Thank you so much, that make sense and worked perfectly.
Ricardo Rodriguez
9,758 PointsRicardo Rodriguez
9,758 Points@chrisfreeman3 @chris freeman
Thank you so much, that make sense and worked perfectly.