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

Garrett Hughes
seal-mask
.a{fill-rule:evenodd;}techdegree
Garrett Hughes
Python Development Techdegree Student 32,971 Points

I have no idea what I'm doing on this exercise. I've watched the video preceding it at least 6 times.

Something's just not clicking with this exercise for me. Haven't had any trouble with python up to this point. I tried to base my answer off what Kenneth did in the video. What am I doing incorrectly here?

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 {name} and I love to eat {food}!"

def string_factory(name = None, food = None):
    list = []
    if name and food: 
        new = template.format(name,food)
        list.append(new)
    return new

1 Answer

I think you misunderstood the challenge.

The function takes in only one argument. It is a list of dictionaries.

Here's a sample parameter:

[{"name": "Michelangelo", "food": "PIZZA"}, {"name": "Garfield", "food": "lasagna"}]

If you call the complete string_factory function with that argument, you should get this in return:

["Hi, I'm Michelangelo and I love to eat PIZZA!", "Hi, I'm Garfield and I love to eat lasagna!"]

Does this help? :smile:

Zachary Crane
Zachary Crane
1,736 Points

That helps a ton! I had no idea what they were asking for either.