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 trialKade Carlson
5,928 PointsNeed help here
I've tried making this work for a couple days now and couldn't get it. I need help on this one
# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Each key will be a Teacher and the value will be a list of courses.
#
# Your code goes below here.
def num_teachers(dictionary):
return len(dictionary.keys())
def num_courses(dictionary):
courses = 0
for item in dictionary:
courses += len(item)
return courses
1 Answer
Ryan S
27,276 PointsHi Kade,
Your logic is on the right track and you almost got it. There is only one minor thing to change.
As you have it right now, when looping through the dictionary, each item
is going to be a key. In order to access the values, use dictionary.values()
, rather than just dictionary
.
Kade Carlson
5,928 PointsKade Carlson
5,928 PointsThank you so much!