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 trial

Python Python Collections (Retired) Dictionaries String Formatting with Dictionaries

'list' object has no attribute 'format'

In my IDE this code work,but in challange not,i don't understand why

strings.py
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
STAFF
Kenneth Love
Treehouse Guest Teacher

As 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 ;)

your function params are wrong way around.

What you mean? This code work in my IDE with same params

In lecture did not say about орdер оf param in function or i miss this.

Bill Talkington
Bill Talkington
11,840 Points

This 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").

Thank Bill, for your support

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Well, yeah. :) All programming requires specific orders to things.

elizabeth gonzalez
elizabeth gonzalez
2,532 Points

I 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...