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

stats - # 5 of 5

I can not figure out what I am doing wrong. I have tried several different things and I have looked through the community for answers - but it is still not working. I felt confident before the fifth task and now I can not seem to get through the code challenge.

teachers.py
def num_teachers(dict):
    num = 0
    for key in dict.keys():
        num += 1
    return num

def num_courses(dict):
    list = []
    for value in dict.values():
        list.extend(value)
    return len(list)

def courses(dict):
    list = []
    for value in dict.values():
        list.extend(value)
    return list

def most_courses(dict):
    max_count = 0
    champion = ""
    for teacher, courses in dict.items():
        if len(courses) > max_count:
            max_count = len(courses)
            champion = teacher
    return champion

def stats(dict):
    master_list = []
    for teacher, courses in dict.items():
        inside_list = [teacher, len(courses)]
        master_list.append(inside_list)
    return master_list

1 Answer

Steven Parker
Steven Parker
231,269 Points

You're code looks OK to me. :+1: So I tested it by copy/pasting directly into the challenge, and it passed!

You might try restarting your browser.

Thank you for letting me know, Steven. I had no idea that there was a bug like that in the code challenges. It was frustrating me. I guess I wasted an hour or so trying to figure out the problem. Oh well, now I know to restart the browser if I ever have a situation like that. Thank you.