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 trialAlejandro Byrne
2,562 PointsWhat am I missing?
My error message says that it didn't get all of the expected output, why? I tried it out in workspaces and it gave me everything I wanted.
# Example:
# values = [{"name": "Michelangelo", "food": "PIZZA"}, {"name": "Garfield", "food": "lasagna"}]
# string_factory(values)
# ["Hi, I'm Michelangelo and I love to eat PIZZA!", "Hi, I'm Garfield and I love to eat lasagna!"]
def string_factory(dictionary):
template = "Hi, I'm {} and I love to eat {}!"
result = [template.format(dictionary[0]["name"], dictionary[0]["food"]), template.format(dictionary[1]["name"], dictionary[1]["food"])]
return result
2 Answers
Anson Tio
5,448 Pointsi think you are supposed to use looping to solve the problem. Consider if you have 3 or more values.
Anson Tio
5,448 PointsGlad to hear that! :D
Alejandro Byrne
2,562 PointsAlejandro Byrne
2,562 PointsThanks! Good suggestion! I used a few other lines to do a for loop and add the dicts to the result, then returned it. It worked. :)