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


I am lost in terms of what i need to do from this step, if someone could help that would be appreciated

def favorite_food(dict):
    return "Hi, I'm {name} and I love to eat {food}!".format()

values = [{"name": "Michael", "food": "PIZZA"}, {"name": "Chisi", "food": "sausage"}]
template = "Hi, I'm {name} and I love to eat {food}!"

def string_factory(values):
    new_list = []
    for each_dict in values:
    return new_list

1 Answer

Hi Mustafa,

Seems like you overcomplicate things a little bit for this challenge.

Your function favorite_food takes a dictionary as its only parameter. So when you call the function you can give it a dictionary as an argument and inside use name and food as the keys.

And now the only thing you have to do is unpack that dictionary with the double asterisks (**) inside of the format method of the function.

def favorite_food(dict):
    return "Hi, I'm {name} and I love to eat {food}!".format(**dict)

favorite_food({"name": "Micheal", "food": "Pizza"}) 

I know packing and unpacking can be a little bit confusing at first, but hopefully this makes some sense!

Ohh I see now how i may have over complicated things thanks a lot. I'm starting to understand packing and unpacking, I'll make sure to practice it a lot more.