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

Matt Wolf
Matt Wolf
2,225 Points

why isn't this working

i had it but then i lost it

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!"]

template = "Hi, I'm {} and I love to eat {}!"
values = [{"name": "Michelangelo", "food": "PIZZA"}, {"name": "Garfield", "food": "lasagna"}]

def string_factory(dictlist):
    stringlist = []
    for item in dictlist:
        stringlist.append(template.format(**item))
    return stringlist

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

your code is fine. i commented out values and still got the error, but passed when i started over again and retyped the function with different variable names. try that.

I'm not exactly sure why I was able to pass it using the change I offered the first time, but now it returns an error, so I've removed my answer. Your solution makes sense in some ways, but I'm not capable of testing things at the moment, so I'll trust your judgement