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 trialnakalkucing
12,964 PointsI'm having trouble with: String Formatting with Dictionaries.
I know that 'continue' is the last thing that python reads in my code but if I put 'return' before continue 'return' will be the last thing it reads and I will only get the first string in a list back. Also it keeps on telling me: Bummer! The output from string_factory()
should be a list. I would really appreciate any help. Thanks. :)
# Example:
# values = [{"name": "Michelangelo", "food": "PIZZA"}, {"name": "Garfield", "food": "lasagna"}]
# string_factory(values)
# ["Hi, I'm Michelangelo and I love to eat PIZZA!", "Hi, I'm Garfield and I love to eat lasagna!"]
template = "Hi, I'm {name} and I love to eat {food}!"
dict_list = [{"name": "Michelangelo", "food": "PIZZA"}, {"name": "Garfield", "food": "lasagna"}]
list1 = []
def string_factory(dict_list):
for dictionary in dict_list:
new_string = template.format(**dictionary)
list1.append(new_string)
continue
return list1
string_factory(dict_list)
1 Answer
John Hughes
Python Web Development Techdegree Student 3,958 PointsHello, You may want to look at the indentation of the return, I don't think you want to return until the for loop has completed. Also you may not need the continue in there. Hope that helps. John
nakalkucing
12,964 Pointsnakalkucing
12,964 PointsThanks. My problem was the indentation of my return. I unindented it and my code passed. Yea! :) Thanks again.