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 honestly don't get this challenge

what am i being asked here? i don't get it.

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!"]

def string_factory(values):
        template = "Hi, I'm {} and I love to eat {}!"
        return template.format(name, food)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You have the basic idea, now add the two missing parts:

  • values will be list of dict. Add a loop to apply each of the name/food combinations to the template
  • create a list of the formatted templates and return it

Post back if you need more help. Good Luck!!

why is it telling me this? I couldn't import string_factory.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

If there is a syntax error then the object string_factory does not get created. This causes the challenge checker to get an NameError due to object not found.

Post your latest code if you need more help. Good luck!!