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

string formatting with dictionaries

I'm getting the error: "What happened to string_factory"?

I can't figure out what the error even means.

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(dicts, string):
  new_list = []
  for items in dicts:
    new_list.append(string.format(**d))
    return new_list

3 Answers

Dan Johnson
Dan Johnson
40,532 Points

It likely can't find string_factory because of a name error, referencing d before it's defined. I imagine you meant to put items there instead.

After you swap that out make sure your return is in the right code block and then you should be good to go.

thanks!