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 trialEnzo Cnop
5,157 PointsIt looks like task 1 is no longer passing.
I did this challenge before and went back for review. I can't figure out what I did wrong this time. The workspace lets task 1 pass, then says task 1 isn't passing when I try to pass task 2. I've tried a few different methods for nesting, but nothing seems to work. Any hints?
player = {"name": "Enzo", "remaining_lives": 3, "levels": [1, 2, 3, 4], dict([["items", "rock"]])}
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Enzo! I feel like you're getting creating a dictionary confused with accessing an element of a dictionary. So I'm going to go over the first step a bit and show you how we would access those dictionaries. I whipped up a small example in workspaces that you should be able to compile and run. My guess is that you will realize the mistake when you see the difference.
player = {"name": "Enzo", "remaining_lives": 3, "levels": [1, 2, 3, 4]}
print(player["name"]) #This prints the value of the player dictionary at the key "name"
print(player["remaining_lives"]) #This prints out the value of the player dictionary at the key "remaining lives"
print(player["levels"]) #This prints out the array associated with the key "levels" from the player dictionary
weapon = {"type": "sword", "details" : {"quality": "fine", "material": "steel"}}
print(weapon["type"])
weapon_details = weapon["details"]
print("Our hero {} is carrying a {} {} {}!".format(player["name"], weapon_details["quality"], weapon_details["material"], weapon["type"]))
What we're going for here is a dictionary inside of a dictionary. You already have a list assigned to a key. Now you just need to assign a dictionary to a key. Take a look at the above example and see if it doesn't clarify things a bit.
Hope this helps!
James Shi
8,942 PointsThe last element in your dictionary doesn't have the proper syntax. You forgot to put a key before the value.