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

Nothing sure what's wrong with my code

error message: string_factory() missing 1 required positional argument: 'string'

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(dicts, string):

    final_list = []

    for item in dicts:
        newlist = string.format(**dicts[dicts.index(item)])

        final_list.append(newlist)

    return final_list

2 Answers

sterling friese
sterling friese
1,145 Points

The exercise asks for one argument to be a dictionary, nothing more. You could simply do:

def string_factory(values):
    return [template.format(**value) for value in values]

A thanks to Matthew Kelty for this solution.

Thank you! I did not expect to use "template" as a given variable. -_-