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 trialVic A
5,452 PointsNot quite sure how to tackle this.
this is as far as i got :/
# 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(**kwargs):
output = []
for i in **kwargs:
output.append(template.format(**kwargs))
2 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou are on the right track. you don't need the word kwargs anywhere. the parameter to the function can be whatever you want, the argument to be passed to the function is the list of dicts. as you loop through the list of dicts, your loop variable will hold each dict and in the loop you basically have that part already, you are appending the template formatted with the two asterisks and the loop variable, so **i to use your loop variable. and then return the answer.
Vic A
5,452 Pointsawesome. Thanks for the explanation. I understand know