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 trialAbdulkadir Kollere
1,723 PointsCases!!
I honestly have no idea what I am required to do in this challenge. I went through the video over and over again and nothing clicked. Kindly assist
# 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):
return **kwargs
john larson
16,594 PointsColby, I know what your saying. Sometimes I get to the challenge and I'm like...wait, did we do this? At this point I just figure were supposed to research stuff and find out. But also the reverse happens in code challenges. We get presented with boatloads of stuff and I'll try to get it all in the challenge answer, and it just wants something basic. w/e :D
1 Answer
john larson
16,594 PointsThe challenge says to pass in name="Kenneth", food="tacos", bit it works without it. But that would look like this:
- def string_factory(dicts, name="name", food="food"):
- I put the pertinent challenge parts next to their respective code
# string_factory accepts a list of dicts
# in the example, values is a list of dicts
# so that will get passed in
def string_factory(dicts): # string_factory accepts a list of dicts
result = [] # Return a new list of strings
for item in dicts: # looping each item in values
result.append(template.format(**item)) # unpacking item
return result
Colby Work
20,422 Pointsthis was frustrating. Like the OP, I watched the video several times, and this answer seems so far off from that, but it works. A more relevant example would probably be useful in the video before the challenge, maybe? Thanks for the help, and comments, john.
john larson
16,594 Pointsjohn larson
16,594 PointsThis will get you started, hopefully someone will give a more insightful answer