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

Hussein Amr
Hussein Amr
2,461 Points

I have no idea what im doing..

I can't understand the question

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(dict_list):
    dict_list = [{"name":"Cunt" , "whore":"Melissa"}, {"name":"Sheniqua" , "whore":"kilopatra"}]

    template = "Hi, I'm {name} and I love to eat {food}!"
string_factory(**{

1 Answer

Moosa Bonomali
Moosa Bonomali
6,297 Points

Take a look at the below code

# 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(dict_list):
    template = "Hi, I'm {name} and I love to eat {food}!"
    #this will hold the output string
    output=[]

    #loop through the dict_list provided and extract each dictionary into "value" variable
    #it will produce a dictionary which we unpack with **value, this will produce name="aaa", food="bbb" like in the                     challenge explanation
    #template.format(**value) will produce the output with the dictionary values inserted, we then add it to the output
    for value in dict_list:
        output.append(template.format(**value))

    return output

values = [{"name": "Michelangelo", "food": "PIZZA"}, {"name": "Garfield", "food": "lasagna"}]
print(string_factory(values))