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 trialBenjamin Cottam
3,162 Pointsstring factory working in Python workspace console but not in challenge
I am not able to get the code to work in the challenge workspace that I am able to get in the console. I get back the "Bummer!'list' object has no attribute 'format' Thanks
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):
new_list = []
for each in dicts:
new_list.append(string.format(**each))
return new_list
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsHi Benjamin, while your code is 100% structurally correct and passes your tests, it has but one flaw: It's not completely to spec. The instructions say to create a function that "accepts a list of dictionaries and a string"... in that order. Your arguments are reversed. This has the challenge tester feeding the dict to your string and visa versa. That is why the list present in each
becomes the "string" that can't be formatted.
This is a very non-obvious error. (and quite a challenge on a Friday!)
Benjamin Cottam
3,162 PointsThank you Chris.