Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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