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 trialKira Pusch
1,139 Pointsunpacking review - invalid syntax???
Just trying to run this python script in response to the packing/unpacking prompt in one of the lectures.
Keeps telling me my "return new_list" line contains invalid syntax but I can't figure out why.
I'm a noob, so all advice is welcome.
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}!"
def string_factory(values):
print(values)
new_list = []
for item in (values):
print(item)
new_list.append(template.format(item['name'], item['food'])
return new_list
1 Answer
Stuart Wright
41,120 PointsThe error message you're getting is a little unhelpful - it tells you that the error is on line 14, but it's actually on line 13. This happens sometimes in Python, because it doesn't notice the error until it's trying to interpret line 14. You're missing a closing brace on line 13. That still won't give you the correct solution, but it should at least help you on your way - will leave to you to see if you can work out the rest, but post again if you need more help.