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

What does this error mean?

My code works perfectly in the worspaces, but here this error comes out: "isinstance() arg 2 must be a type or tuple of types"

What's happening?

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}!"


list = []
def string_factory(aaa, bbb):
  for i in range(len(aaa)):
    a = bbb.format(**aaa[i])
    list.insert(1,a)
  return list

string_factory(dicts, string)

what does ** do and why are aaa and bbb in there ?

1 Answer

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

Your answer is almost correct, the new list must be created inside the function though, it is very bad practice to create functions that rely on global variables.

#list = []    #this is a global variable, the function must return a new variable, not return a global one
def string_factory(aaa, bbb):
  list = []    #we create a new list
  for i in range(len(aaa)):
    a = bbb.format(**aaa[i])
    list.insert(1,a)
  return list

#string_factory(dicts, string)   #not neccessary for the quiz

PS: ~Please fix the markdown teamtreehouse.~ Fixed! - KL