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 trialGilang Ilhami
12,045 PointsString formatting with dictionaries
I tried doing the loop, but i just can't get it, am i missing something?
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):
new_list = []
for words in dicts:
new_list = string.append(sting.format(**dicts))
return new_list
print (string_factory(dicts, string))
2 Answers
Steven Parker
231,236 PointsYou're closer, but you have a few syntax issues yet.
Ignoring the print statement at the end, which is not part of the challenge but doesn't hurt it, your remaining issues are all in the statement inside the loop:
new_list = string.append(sting.format(**dicts))
- you can't "append" a string, you probably want to append the new_list (instead of assigning to it)
- you spelled "sting" (without the "r") where you apply format to it.
- your loop extracts the individual dictionaries as "words", but the format still attempts to use dicts.
Gilang Ilhami
12,045 PointsThank you steven, i was wondering if you can help me witht he 4th callenge?
def courses(my_dict):
single = []
for value in my_dict.values():
single.append(value)
return value