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 trialJoëlle Galloux
556 PointsI can't figure out why this answer is wrong?
Hi there!
I tested my code for this question and was able to return the correct teacher's name. But I get an error when submitting the answer here.
Thanks for your help!
# 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):
count = 0
for teach in teachers:
count +=1
return count
def num_courses(teachers):
count1 = 0
for value in teachers.values():
count1 += int(len(value))
return count1
def courses(teachers):
list_of_all_courses = []
for value in teachers.values():
list_of_all_courses.extend(value)
return list_of_all_courses
def most_courses(teachers):
max_courses = max(teachers.values())
for teacher in teachers:
for value in teachers.values():
if value == max_courses:
return teacher
1 Answer
Steven Parker
231,269 PointsThe challenge probably uses a different data set to test with than you did. Yours just happened to return the correct result.
The issue is that applying "max" to "teachers.values" will give you the list the comes last alphabetically, not necessarily the largest one. Remember, in "num_courses" you applied the "len" function to each list to get the count. You may need to do something similar here.