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 Factory Code Challenge- I think I'm missing something here?

This is what I have:

```string = "Hi, I'm {name} and I love to eat {food}!" def function "string_factory" = (string.format(**dicts))

but I am getting a syntax error, which I can't copy without canceling the post. 

I think I'm just missing something here.

1 Answer

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

This is the answer:

def string_factory(my_list_dicts,my_string):  #a list of dicts and a string
  aux_list = [] #we create an empty list to be filled

  for index in range(len(my_list_dicts)):   #we iterate over the list of dicts
    new_string = my_string.format(**my_list_dicts[index]) #we unpack each dict's contents on the string
    aux_list.append(new_string)  #we add the string to the list

  return aux_list