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

Not Sure why i get this error

Why Am i getting a Bummer! saying "What Happened to string_factory()?"

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): 
  string_list = []
  for i in range(len(dictionary)):
    string_list.append(strings.format(**dictionary[i]))
  return string_list

2 Answers

Thomas Kirk
Thomas Kirk
5,246 Points

Hi,

The arguments in your function are 'dicts' and 'string', but elsewhere in your function you refer to them as 'dictionary' and 'strings'

Santos Solorzano
Santos Solorzano
3,125 Points

Hello,

The only thing I would change would be your for-loop. Everything else is dandy. Try something like this:

for items in dicts:
    string_list.append(string.format(**items))
return string_list

To quote Kenneth in one of his answers, "Your for loop is going through the list of dictionaries, so each items in it is a dictionary."

Also note that you used "string" as your function parameter in your definition, but you used "strings" with the format() method inside the for-loop of your function block.