Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Dictionaries Dictionary Basics

issues 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."

dicts.py
player = {"name": "joe", "remaining_lives": 3 "levels": 1, 2, 3, 4}
new = {"items": "bluey", "up": "away"}

3 Answers

Aaron Nolan
Aaron Nolan
5,714 Points

Okay 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
Aaron Nolan
5,714 Points

So 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 :)

When 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
Aaron Nolan
5,714 Points

Can you post what code you have now and I will help you troubleshoot it :)

why did you use square brackets instead of curly brackets, around the numbers?

Aaron Nolan
Aaron Nolan
5,714 Points

So 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 :)

player = {"name": "joe", "remaining_lives": 3}
player["levels"] = [1, 2, 3, 4]