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 trialJoel Price
13,711 Pointsstring_factory() missing 1 required positional argument: 'dicts' error. I think I have the required argument, however.
This is what I've got. Can anyone see why I'm getting this?
Thank you.
# 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(string, dicts):
holding = []
for dict in dicts:
holding.append(string.format(name=dict["name"], food = string["food"]))
return holding
3 Answers
james south
Front End Web Development Techdegree Graduate 33,271 PointsJoel Price almost there....you're calling the format method correctly, except you are calling it on string. what is string? you want to format the template and append that.
Tapiwa Lawrence Konga
5,277 Pointsuse holding.append(template.format(**dict))
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou are close. your function should only take one argument, the list of dicts. then in your loop, the template formatted with the two asterisks and the loop variable is what you append to your new list.
Joel Price
13,711 PointsSo I think I understand what you're saying and I've made a few changes.
template = "Hi, I'm {name} and I love to eat {food}!"
def string_factory(dicts):
holding = []
for dict in dicts:
holding.append(string.format(**dict))
return holding
Only now I get a: I couldn't import string_factory
. error. Is the problem still with my .append()?