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 trialMark Nembhard
1,387 Pointshow to access the keys only in a dictionary?
It just gives you the dot following student space indicating there is a method. I am not aware of any other method apart from the items one
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsGood question.
- access key, value pairs using
dict.items()
- access keys only using
dict.keys()
- access values only using
dict.values()
Post back if you need more help. Good luck!!!
Mark Nembhard
1,387 PointsIt wasn't obvious to me alas but i got there in the end with your help. Things seem a lot more easier when you know how and the opposite is true also. Anyway the upshot is that they are going to relay my complaint to the instructor to possibly amend the course once they double check, Thanks again.
Mark Nembhard
1,387 PointsMark Nembhard
1,387 PointsThank you. I don't recall these being mentioned in the previous video in the training. If it is the case then this is one for the course managers to update.
Mark Nembhard
1,387 PointsMark Nembhard
1,387 PointsHi Chris. doe snot accept this answer as there is a .___() already. SO you cannot have a .dict.keys() fro an answer. Another way was to print (dic. iname ), as in name of the dictionary. which would print but it is not a print statement. How do i get the question i am doing copied again so that you can see what i mean.. I solved it
It asks a similar following question but wants the values thistime and not the key and it this is what it accepted "val in student.values():". Where student is the dictionary variable. This is not fair as it was not explicitly shown in the videos. I will double check but i have already been over the video. Thanks i still would not of got the solution if it were not for your help. made me rethink what it could be. Frustrating as this is so entry level and i want get going
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsI thought it was obvious from my answer that I was showing the forms of an answer and that you would understand that what you are looking for would be one of: items or keys or values