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 trialAbdullah Jassim
4,551 PointsI ran this in SHELL and I get the wrong answer. But I dont get whats wrong with the logic?
def most_courses(arg):
keys_max = max(arg.keys())
return keys_max
def num_teachers(arg):
teachers = int(len(arg))
return teachers
def num_courses(arg):
count_courses = 0
for values in arg.values():
for number in values:
count_courses += 1
return count_courses
def courses(arg):
single_list = []
for course in arg.values():
single_list.extend(course)
return single_list
def most_courses(arg):
keys_max = max(arg.keys())
return keys_max
# 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.
1 Answer
Steven Parker
231,269 PointsWhen you perform the "max" function on the keys, it does not count the values. Instead, it will compare the keys themselves. And since the keys are strings, the "max" will be the one that comes last in the alphabet.
Abdullah Jassim
4,551 PointsAbdullah Jassim
4,551 PointsI am not sure how to tackle this one. I have read other answers but it seems a little complicated. Any direction would help.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYou'll probably want to use a loop, you had one for the last couple of tasks. But for this one, you might want to use the dictionary "items" to get the teacher and courses at the same time:
for teacher, courses in arg.items():
Then, the instructions give you a good hint: "You might need to hold onto some sort of max count variable." By comparing a saved count with the number of courses in the loop, you can determine when to update the count and save the teacher's name. When the loop ends, the last saved teacher's name should be the one with the most courses.