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 trialTodd Anderson
4,260 PointsI do not understand the question. Could it be worded in a different way?
I'm not exactly sure what the question is asking me. I've tried a bunch of different solutions and re-watched the videos prior to the challenge, but that did not help me get through this.
# 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(*values):
new_list = []
if name and food:
new_list.append(template.format(**args))
return new_list
2 Answers
Steven Parker
231,269 PointsThe instructions are very specific, and your issues seem to be more about basic structure. Perhaps a few hints will help:
- you won't need a packing operator ("*") with the parameter
- you don't need to change (un-comment) any of the provided code and comments
- you don't need a conditional ("if"), but you will need a loop
- the append/template line looks good but you didn't define "args" yet
- the return should always be done last (it is indented too far)
Todd Anderson
4,260 PointsThank you.
I originally tried a loop as well and got an error that not all of the items were found. This example is vague considering watching all of the videos prior did not help me solve the challenge. In the video right before this challenge he uses *kwargs in the parameter. So by doing that and then asking to separate items with * it is confusing as to what exactly needs to be done. So far an example has not left me feeling this lost.
I figured it out, I just think that the wording is confusing the way it is written. Also, I did not know you could use dicts as an iterator. Thanks James.
Steven Parker
231,269 PointsNow that you've solved it, can you think of a better way to phrase the instructions?
James Morris
5,104 PointsJames Morris
5,104 PointsHi Todd,
You don't want an IF statement there, you want a for loop to cycle through each dict in the list. I try and comments at each step so I know what I've got so far. e.g.
Good luck mate!