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 trialOleh Kalyuzhnyy
1,874 Points'list' object has no attribute 'format'
In my IDE this code work,but in challange not,i don't understand why
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(in_str,some_dict):
new_list=[]
for val in some_dict:
new_list.append(str(in_str.format(**val)))
return new_list
6 Answers
Kenneth Love
Treehouse Guest TeacherAs the prompt says (and shez azr said), the list of dictionaries comes first and the string comes second. Your IDE really doesn't have any say in this matter ;)
shezazr
8,275 Pointsyour function params are wrong way around.
Oleh Kalyuzhnyy
1,874 PointsWhat you mean? This code work in my IDE with same params
Oleh Kalyuzhnyy
1,874 PointsIn lecture did not say about орdер оf param in function or i miss this.
Bill Talkington
11,840 PointsThis was stumping me too; I made the same error. Treehouse's answer-checking script is expecting the inputs in a specific order ("...accepts a list of dictionaries and a string").
Oleh Kalyuzhnyy
1,874 PointsThank Bill, for your support
Kenneth Love
Treehouse Guest TeacherWell, yeah. :) All programming requires specific orders to things.
elizabeth gonzalez
2,532 PointsI found this one very challenging (I am a newbie but I watched the videos and research before asking for help.) This was my answer and it worked
def string_factory(dicts, strings):
fillin = []
for keys in dicts:
fillin.append(strings.format(**keys))
return fillin
What I didnt know was to do the fillin.append(string.format(**keys)) I found on stack overflow something similar and was able to grasp how to finish this challenge. Like I never knew I could use list.append(second_list.format()) a nice thing to know...