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 Introducing Dictionaries Iterating and Packing with Dictionaries Recap of Iterating and Packing with Dictionaries

Mark Nembhard
Mark Nembhard
1,387 Points

how 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
MOD
Chris Freeman
Treehouse Moderator 67,464 Points

Good 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
Mark Nembhard
1,387 Points

Thank 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
Mark Nembhard
1,387 Points

Hi 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
Chris Freeman
Treehouse Moderator 67,464 Points

I 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

Mark Nembhard
Mark Nembhard
1,387 Points

It 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.