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 trialDylan Fried
3,123 PointsNeed help with task 2 in teachers.py
I was wondering if someone can give me a hint on what to do next. In my code I thought if I obtain the values of the dictionary and then converted it length; I'll be able to get the number of courses there are. However, the output was 2 but I need the output to be 4. How would I be able to count the number of courses for two lists inside a dictionary?
# 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.
Teachers = {"Andrew Chalkley": ["jQuery Basics", "Node.js Basics"], "Kenneth Love": ["Python Basics", "Python Collections"]}
def num_teachers(Teachers):
Teach = Teachers.keys()
numOfTeachers = len(Teach)
return numOfTeachers
def num_courses(Teachers):
course = Teachers.values()
numOfCourse = len(course)
return numOfCourse
1 Answer
Steven Parker
231,269 PointsThe main thing is to consider that there will be only one "value" per teacher. But the values are lists, and the number you want will be the sum of number of items in each of the lists.
From there, you have a number of choices of implementation strategy, but the most basic might be a loop.
Dylan Fried
3,123 PointsDylan Fried
3,123 PointsOkay, thank you!