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 trialilya A
3,802 Pointsissues with dictionary basics (task 2)
I have tried to nest the "new" dictionary in the old one but I am still getting the same error: "Oops! It looks Task 1 is no longer passing."
player = {"name": "joe", "remaining_lives": 3 "levels": 1, 2, 3, 4}
new = {"items": "bluey", "up": "away"}
3 Answers
Aaron Nolan
5,714 PointsOkay so now for the final part of the question you need to add another key to the dictionary items which is another dictionary with whatever key and value you like! This can be added like so:
player["items"] = {"snacks": "apple"}
Hope this helps! Happy coding! :)
Aaron Nolan
5,714 PointsSo in this question, Treehouse doesn't want you to simply add the new key and value onto the end of the dictionary in the declarement. They would rather you add it in a new statement. So for example, to add the list of levels would be done like so:
player = {"name": "joe", "remaining_lives": 3}
player["levels"] = [1, 2, 3, 4]
Hope this helps and if you need anymore assistance feel free to ask!
Happy Coding :)
ilya A
3,802 PointsWhen I use this code I get an error:
"Bummer! KeyError: 'items'"
These are the instructions:
"...add a "levels" key. It should be a list with the values 1, 2, 3, and 4 in it. And, lastly, add an "items" key. This key's value should be another dictionary. Give it at least one key and value, but they can be anything you want."
Aaron Nolan
5,714 PointsCan you post what code you have now and I will help you troubleshoot it :)
ilya A
3,802 Pointswhy did you use square brackets instead of curly brackets, around the numbers?
Aaron Nolan
5,714 PointsSo curly braces are used to define dictionaries in Python while square braces are used to define lists. The question asks you to add the key levels with a value of a list and the next part asks you to add the key items with the value of another dictionary so thats why the different brackets are used!
player = {"name": "joe", "remaining_lives": 3}
player["levels"] = [1, 2, 3, 4]
player["items"] = {"snacks": "apple"}
Hope this information clears everything up :)
ilya A
3,802 Pointsplayer = {"name": "joe", "remaining_lives": 3}
player["levels"] = [1, 2, 3, 4]