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

teacher stats 5:5

I can't seem to figure out what's wrong with the last part of this code. can someone help me? everything else seems to pass except this last one

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(teach_dict):
    return len(teach_dict)

def num_courses(teach_dict):
    course_num = 0
    for teacher in teach_dict:
        for course in teach_dict[teacher]:
            course_num += 1
    return course_num

def courses(teach_dict):
    class_list = []
    for teacher in teach_dict:
        for course in teach_dict[teacher]:
            class_list.append(course)
    return class_list

def most_courses(teach_dict):
    most = 0
    for teacher, courses in teach_dict.items():
        if len(courses) > most:
            most = len(courses)
            name = teacher
    return name

def stats(teach_dict):
    list_of_lists = []
    for teacher, courses in teach_dict.items():
        single_list = [teacher, len(courses)]
        list_lists.append(single_lists)
    return list_of_lists

2 Answers

Nicholas Ward
Nicholas Ward
5,797 Points

Your logic is totally correct, but just a small syntax error. Just change list_lists.append(single_lists) to list_of_lists.append(single_list)

(fix list_of_list and remove the 's' from single_lists)

it says it can't find 'stats'

Nicholas Ward
Nicholas Ward
5,797 Points

I tested your exact code with those two changes I mentioned above, and it should pass all five challenges. Sometime the Challenge "Bummers" are not very useful for determining the actual issue. It will often say "can't find function" if there is a syntax error within the function block. Hope that helps!

hmm ok. i'll try again. but yes it helps