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 trialAsher Orr
Python Development Techdegree Graduate 9,410 PointsIterating over only the keys in a dictionary - is there an alternate way to do this, or is there an error w/ this quiz?
Hi everyone! On this quiz, the question asks:
Complete the code so it will iterate over only the keys in the student dictionary.
student = {'name': 'Craig', 'major': 'Computer Science', 'credits': 36}
for key in student.#in between these hashtags, there is a space where you enter your answer#():
print(key)
I thought the way to complete this code is:
student = {'name': 'Craig', 'major': 'Computer Science', 'credits': 36}
for key in student:
print(key)
I ran this in my workspace, and it returned only the keys. I think the quiz may have an error, because it currently forces user to enter text after "student." in the for loop.
To complete the challenge, you could just replace the period after "student" with a colon.
Is this correct? Or am I missing something about iterating over only the keys in the student dictionary?
1 Answer
Steven Parker
231,275 PointsJust naming the dictionary would also do the same job, but since there's a membership operator before the blank, they are expecting you to use the "keys()" method there.
Asher Orr
Python Development Techdegree Graduate 9,410 PointsAsher Orr
Python Development Techdegree Graduate 9,410 PointsThank you so much, Steven! That resolved the issue. I appreciate you!