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

Saul Goldman
Saul Goldman
1,539 Points

please help with the dictionary challenge?

if you could also explain a bit whats going on that would be amazing, thank you so much

string_factory.py
def favorite_food(dicts):
    for each_dict in dicts:
        if name and food in each_dict:
            return "Hi, I'm {name} and I love to eat {food}!".format(name, food)

1 Answer

Steven Parker
Steven Parker
231,236 Points

I was going to ask you "what's going on", particularly with this line:

        if name and food in each_dict:

I'm pretty sure it doesn't do it, but what did you want that line to do?

But the best hint I can think of is this: to pass this challenge, you only need to correctly fill in the argument to "format", no other code is needed.