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 trial

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

Harris Handoko
Harris Handoko
3,932 Points

Quiz question on Dictionary: player["weapons"]["sword"]

player["weapons"]["sword"]

The above code would work with which of the dictionaries below?

B.

player = {
"weapons": ["sword", "bow", "stick"] }

Why is B the wrong choice? I could retry the quiz two more times, but I don't think I will learn anything if it just says "Sorry, the answer is incorrect" as feedback. Thanks!

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Harris,

You can use "weapons" to index into player because player is a dictionary. However, "sword" is in a list, and you can only index into lists using their position. For example: player["weapons"][0].

Hope that helps,

Cheers

Alex