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

Syntax error?

When I print this last function (stats) in Workspaces, it seems to create lists within lists as asked for in the question.

I'm getting this as my output, but getting a "Bummer: try again" message: [['name_of_teacher_1': number_of_courses_1], ['name_of_teacher_2': number_of_courses_2]]

teachers.py
def num_teachers(a_dict):
    return len(a_dict)

def num_courses(a_dict):
    total = 0
    for value in a_dict.values():
        total += len(value)
    return total

def courses(a_dict):
    my_list = []
    for course in a_dict.values():
        my_list += course
    return my_list

def most_courses(a_dict):
    maximus = 0
    for teacher, course in a_dict.items():
        if len(course) > maximus:
            maximus = len(course)
            teacher_name = teacher
    return teacher_name

def stats(a_dict):
    my_list = []
    for teacher, course in a_dict.items():
        my_list.append([teacher, len(course)])
    return my_list

1 Answer

Hmm. Ok thanks - I was tearing my hair out on this one!

Buggy code checker :(

It's passed now.