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 (2016, retired 2019) Dictionaries String Formatting with Dictionaries

Douglas North
Douglas North
10,884 Points

I cannot see what's wrong with my answer

Hey there,

I cannot find the problem. I use pycharm to test it and get a good result. it responds with "Bummer! 'Name'"

string_factory.py
dicts = [
    {'Name':'Michelangelo','food':'PIZZA'},
    {'Name':'Garfield','food':'Lasagna'},
    {'Name':'Popeye','food':'Spinach'},
    {'Name':'Doug','food':'Kebab'},
    ]

def string_factory(dicts):
    string = "Hi, I'm {Name} and I love to eat {food}!"
    new_list =[]
    for elem in dicts:
        new_list.append(string.format(**elem))
    return new_list

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Douglas, there's 2 small issues with your code.

I've commented them below:

def string_factory(dicts):
    string = "Hi, I'm {Name} and I love to eat {food}!"  #  template variable is provided to us
    new_list =[]
    for elem in dicts:
        new_list.append(string.format(**elem))  # rename string to use template variable
    return new_list

With changes made:

template = "Hi, I'm {name} and I love to eat {food}!"

def string_factory(dicts):
    new_list =[]
    for elem in dicts:
        new_list.append(template.format(**elem))
    return new_list
Douglas North
Douglas North
10,884 Points

thanks! switched it up and works. I had to lowercase the N in name also