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

No idea what the system wants.

I keep getting the following message:

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

Please help.

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

dicts = [
    {'name': 'Michelangelo',
     'food': 'PIZZA'},
    {'name': 'Garfield',
     'food': 'lasanga'},
    {'name': 'Walter',
     'food': 'pancakes'},
    {'name': 'Galactus',
     'food': 'worlds'}
]

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

def string_factory(my_string, my_dict):
    my_list = []

    for key in my_dict:
        my_list.append(my_string.format(**key))

    return(my_list)

1 Answer

Steven Parker
Steven Parker
231,269 Points

:point_right: Your function takes the wrong number of arguments.

The challenge asks you to create a function "that accepts a list of dictionaries as an argument". It may be a list, but it's just one argument.

The function you have above takes two arguments (my_string and my_dict). So when the challenge tries to test it by passing a single argument, that's why you see the error complaining about missing an argument.

Also, you should not alter the code provided by the challenge. In this case, the name of template string should still be "template". And where did this "dicts" come from? It's neither provided, nor asked for in the challenge. It looks like it came from the retired version of this course (but that's not what your link points to). Are you trying to work both versions at once?

Thank you for a quick response!

When I try to keep one argument instead, I get the following message: Bummer! I couldn't import string_factory.

Steven Parker
Steven Parker
231,269 Points

You might want to post a new question.

Include your revised code, and make sure you're working on the correct version of this course!

Thank you Steven! I tried to use variable names from the example, and it worked.