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

Stuck on code challenge: String Formating with Dictionaries

I am not sure what I am doing wrong. I tried this code on eclipse with return replaced with print on line 20, and I believe that the results are what the task is asking me to do.

When I try to check the work in the treehouse I get this

Bummer! string_factory() missing 1 required positional argument: 'template'

I am not sure what I am doing wrong. I would really appreciate some guidance.

# 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!"]
dicts = [
    {'name': 'Kenneth',
     'food': 'tacos'},
    {'name': 'Michelangelo',
     'food': 'PIZZA'},
    {'name': 'Garfield',
     'food': 'lasagna'},

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

def string_factory(dicts, template):
    list = []
    for item in dicts: 
    return list

string_factory(dicts, template)

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

You are So close! You do not need to pass template as a parameter. It can be referenced directly as a global variable.

Also, it's a good practice to avoid using built-in keywords or types as variable names. list is the built-in type list. It's better to use a variable name that better represents what's contained in the list. "results" or "result" is often used.

Thank you! I was stuck on this problem for 2 days and finally solved with your help.

If it is not too much to ask, can you explain what the error(positional argument) was saying so that I will be able to fix this in the future?