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 trialPaul Ownby
23,414 PointsTeacher Stats: 4 of 5 - My solution seems to work in workspaces but fails in the challenge. What am I doing wrong?
Here is the function I added: def most_courses(courses): max_count = 0 for teacher in courses: if len(courses[teacher]) > max_count: max_count = len(courses[teacher]) max_teacher = teacher return max_teacher
I have tested this in workspaces with several iterations and seem to get the right response
# 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(teachers):
return len(teachers)
def num_courses(teachers):
total_courses = 0
for teacher in teachers:
total_courses += len(teachers[teacher])
return total_courses
def courses(courses):
all_courses = []
for teacher in courses:
all_courses += courses[teacher]
return all_courses
def most_courses(courses):
max_count = 0
for teacher in courses:
if len(courses[teacher]) > max_count:
max_count = len(courses[teacher])
max_teacher = teacher
return max_teacher
1 Answer
Steven Parker
231,248 PointsYou're returning inside the loop.
But you probably want to wait until the loop has checked all the values and finishes, and then return.
Paul Ownby
23,414 PointsPaul Ownby
23,414 PointsThanks! That was it!