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 trial

Python Python Collections (2016, retired 2019) Dictionaries String Formatting with Dictionaries

Alejandro Byrne
Alejandro Byrne
2,562 Points

What 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.

string_factory.py
# 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
Anson Tio
5,448 Points

i think you are supposed to use looping to solve the problem. Consider if you have 3 or more values.

Alejandro Byrne
Alejandro Byrne
2,562 Points

Thanks! 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. :)

Anson Tio
Anson Tio
5,448 Points

Glad to hear that! :D