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 triallukeoberrieder3
2,261 PointsBummer! Didn't get the right teacher name!
Just using the max() function to find the biggest dictionary in the dictionary of course. This works when I mess around with the teacher/course list. The test checker tells me that it doesn't get the right teacher name. Could someone explain what I need to do differently? Thanks!
# 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_dict):
teacher_counter = 0
for key in teachers_dict.keys():
teacher_counter += 1
return(teacher_counter)
def num_courses(teachers_dict):
total_course_list = []
total_course_list_combined = []
for x in teachers_dict:
total_course_list.append(teachers_dict[x])
for y in total_course_list:
total_course_list_combined += y
return(len(total_course_list_combined))
def courses(teachers_dict):
total_course_list = []
total_course_list_combined = []
for x in teachers_dict:
total_course_list.append(teachers_dict[x])
for y in total_course_list:
total_course_list_combined += y
return(total_course_list_combined)
def most_courses(teachers_dict):
return(str(max(teachers_dict)))
2 Answers
James Shi
8,942 PointsThe max functions finds the "largest" key in the dictionary. In this case, it's returning the name of the teacher that comes last alphabetically. You should iterate through each teacher, count the number of courses for each teacher, and return the name of the teacher with the most courses.
Shannon Simpson
4,454 PointsThis code takes a dictionary (dct), the name (name) of every teacher in the dictionary in turn, and assigns the list of that name to teacher. Then, it returns the length of teacher + 1. The last part is where you you want to check the number of items in dct Like this:
def num_teachers(dct):
for name in dct:
teacher= dct[name]
return len(teacher) + 1;
def num_teachers(dct):
return len(dct)