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

John DiGiovanni
PLUS
John DiGiovanni
Courses Plus Student 902 Points

Confusion as to what exactly this exercise is looking for

Hi, I think Iā€™m confused as to what exactly this exercise is looking for. Do they want me to actually run the function?

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):
    if name and food:
        return("Hi, I'm {} and I love to eat {}!".format(name, food))
    else:
        return("Ew what is wrong with you.")
Michael Hulet
Michael Hulet
47,913 Points

Hey John!

In the future, please refrain from posting profanity in your questions, comments, answers, and any associated code. I've removed the offending phrasing from the last line of the code above

1 Answer

Michael Hulet
Michael Hulet
47,913 Points

Nice answer! I turned this comment into an answer so it could be upvoted and marked as best (which it should be imo, but that's up to OP). I also marked your answer in the thread you linked as best, as it's what fixed that OP's problem (and is also one of the general best answers I've seen on this site in a long time)

AJ Salmon
AJ Salmon
5,675 Points

Thank you Michael, I appreciate that!

Steven Parker
Steven Parker
231,275 Points

That other answer certainly gives a new meaning to the word "thorough"! :wink: