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 trialEvandro Luis Lima Pastor
1,061 PointsWhat happening with string_factory?
Hello,
I'm so frustrated! I spend 2 hours to try to figure out what is wrong with my code.
The problem is with the sintax, logic or both? Any direction will be most appreciated. :)
dicts = [
{'name': 'Michelangelo',
'food': 'PIZZA'},
{'name': 'Garfield',
'food': 'lasanga'},
{'name': 'Walter',
'food': 'pancakes'},
{'name': 'Galactus',
'food': 'worlds'}
]
string = "Hi, I'm {name} and I love to eat {food}!"
def string_factory(string, dicts):
for key, elem in disct.items():
lista = {name:food}
result = string.format(**lista)
return result
2 Answers
Boris Ivan Barreto
6,838 PointsOn this exercise, you should return a list
dicts = [
{'name': 'Michelangelo',
'food': 'PIZZA'},
{'name': 'Garfield',
'food': 'lasanga'},
{'name': 'Walter',
'food': 'pancakes'},
{'name': 'Galactus',
'food': 'worlds'}
]
string = "Hi, I'm {name} and I love to eat {food}!"
def string_factory(dicts, string):
new_list = [] # define an empty list
for items in dicts:
new_string = string.format(**items)
new_list.append(new_string)
return new_list
Evandro Luis Lima Pastor
1,061 PointsHey @Anthony! Thanks for the tips... My code not work still. @Boris! The solution was so simple that I have to bang my head into the wall! Thanks for the tip. :D
Anthony Romero
6,364 PointsAnthony Romero
6,364 PointsI'm having trouble with the same exercise too. I saw that you spelled dicts wrong in you for loop. It also looks like you've indented your return too far in and made it part of your for loop.