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

Robert Hecht
Robert Hecht
6,797 Points

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

My answer looks exactly like the example and what they tell me it should look like in the Bummer example. What am I missing?

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

2 Answers

Steven Parker
Steven Parker
231,275 Points

The example is not a solution to the challenge, it's only to illustrate how the arguments are used by the "format".

Your task is to provide values to the "format" that come from the "dict" that is provided as an argument to the "favorite_food" function. Hint: the instructions talk about "unpack that dictionary" so the "splat" operator ("**") might be useful.

Hi there! The challenge is not asking you to copy what the example looks like, unfortunately. The challenge is asking you to unpack the dictionary that is passed in to the function. This automatically fills in the "name" and "food" placeholders. Check the teachers notes of the previous video.