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

Holden Glass
Holden Glass
6,077 Points

code challenge being stubborn, possibly.

I wrote this code according to the challenge and It checked out in workspaces(it printed out and didn't throw and exception) but it won't work in the challenge. It says the output of string_factory() should be a string. I don't know what else to do.

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(ld, s):
    for dit in ld:
        return str(s.format(**dit))

1 Answer

Steven Parker
Steven Parker
231,236 Points

:point_right: The challenge says "The output from string_factory() should be a list" (not string).

So you'll need a list in which you can collect the strings produced inside the loop, and then you will return only after the loop has completed. Also, formatting a string returns a string, so you won't need to convert it using str().

Also, are you aware that there is a newer version of this course?

Holden Glass
Holden Glass
6,077 Points

1) I just figured that out. Thank you though.

2) I am aware but I am doing this one because it is here and I will have an easer time with the newer one.