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 trialJinman Kim
5,586 PointsCorrect output but incorrect answer
I am not sure why this answer is not correct. I have submitted support as I thought it was a bug but they say other people was able to pass the test so I might be missing something
def favorite_food(name, food):
print ("Hi, I'm {} and I love to eat {}!".format(name,food))
favorite_food(**{"name":"Jin", "food":"Bacon"})
1 Answer
Cheo R
37,150 PointsKey part is:
Your function should unpack that dictionary
Remember, that using curly braces with strings, you can refer to your variable substitutions by name and use them in any order you want.
"Hi, I'm {name} and I love to eat {food}!".format()
And you can use double asterisks to unpack dictionaries (keyword arguments).
def unpack(dictionary):
return "{I} {am} {num} {a} {dictionary} {num}".format(**dictionary)
print(unpack({'I': 'yo', 'am': 'soy', 'a': 'un', 'dictionary': 'dictionario', 'num': 5}))
# yo soy 5 un dictionario 5
Jinman Kim
5,586 PointsJinman Kim
5,586 PointsAh I see more clearly how unpacking is done now. Thanks a lot!