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 trialMartin Batista
4,606 PointsGetting the following error: string_factory() missing 1 required positional argument: 'template'
Here's my code:
values = [{"name":"Sam","food":"Pizza"},{"name":"Sally","food":"Spaghetti"}] template = "Hi, I'm {name} and I love to eat {food}!"
def string_factory(dicts, string): # args_as_list = list(args) holding_list = [] for entry in dicts: holding_list.append(string.format(name=entry['name'], food=entry['food'])) return holding_list
function call
string_factory(values, template)
I tested it in the python console it ran fine.
thanks for your help!
# 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!"]
values = [{"name":"Sam","food":"Pizza"},{"name":"Sally","food":"Spaghetti"}]
template = "Hi, I'm {name} and I love to eat {food}!"
#def string_factory(**kwargs):
def string_factory():
holding_list = []
for entry in values:
holding_list.append(template.format(name=entry['name'], food=entry['food']))
#holding_list.append(template.format(**entry))
return holding_list
# function call
string_factory(values, template)
1 Answer
Aldrin Mabanta
11,768 PointsHi Martin,
I got the same error - so what I did is re-read the question like 3 times and I caught it.
The values(dict) and the template(string) is declared globally. However, the challenge question is asking for (see below)
"Write a function named string_factory that accepts a list of dictionaries as an argument. Return a new list of strings made by using ** for each dictionary in the list and the template string provided."
It's asking for 1 argument. So when you call the function, just pass 1 argument which is "values" and you'll be fine.
I tried this in Workspaces both w/ 1 argument string_factory(values) and 2 arguments(values, template) and they both worked. However, for this code challenge, they are more stricter.
Hope that helps you out.
Cheers!