Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Dictionaries String Formatting with Dictionaries

I am not sure what to do?

I am not sure what to do because I thought I had unpacked a dictionary but obviously I didn't. I am a bit confused

def favorite_food(dict):
    if dict:
        return "Hi, I'm {name} and I love to eat {food}!".format()                                           
        print("Hi what is ur name and what food would you like to eat?")

favorite_food(**{"dict": {"name": "Kenneth", "food": "tacos"}})

2 Answers

Steven Parker
Steven Parker
216,032 Points

You're overthinking this a bit. You won't need to add a conditional statement. In fact, the only thing you need to add is to pass an argument to the "format" function in the provided code. That's the place where you can use the unpacking operator with the "dict" parameter.

Jenn Chu
Jenn Chu
Courses Plus Student 18,400 Points

Try this:

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

Steven Parker
Steven Parker
216,032 Points

:warning: FYI: Explicit answers without any explanation are strongly discouraged by Treehouse and may be subject to redaction by staff or moderators.