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 trial

Python Python Collections (2016, retired 2019) Dictionaries Teacher Stats

David Lahoud
David Lahoud
1,408 Points

Please explain what I am doing wrong with this code

I don't understand why my code at the bottom is not working for this question, it seems that it should be working and that it makes sense but I keep getting the bummer try again message.

teachers.py
# 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):
    return sum(len(v) for v in teachers.values())

def courses(teachers):
    output = []
    for value in teachers.values():
        output += value
    return output

def most_courses(teachers):
    max_count = 0
    rockstar = ""
    for teacher, course_list in teachers.items():
        if len(course_list) > max_count:
            max_count = len(course_list)
            rockstar = teacher
    return rockstar

2 Answers

Steven Parker
Steven Parker
231,269 Points

Your code looks good to me. So I tried pasting it directly into the challenge and it passed the first 4 tasks!

So try again, maybe after restarting your browser.

Susan krystof
PLUS
Susan krystof
Courses Plus Student 2,662 Points

Your code is good, restart your browser or clear the code and write it again.