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

Derek McCool
Derek McCool
12,289 Points

Couldn't find 'most_courses'

I am getting an error, Bummer! Couldn't find 'most_courses' and I cannot seem to figure out why.

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(dict): 
    count= 0
    for key in dict:
        count +=1
    return count



def num_courses(dict):
    course_count = []
    for teachers in dict:
        for courses in dict[teachers]:
            course_count.append(courses)
    return len(course_count)

def courses(dict):
    course_count = []
    for teachers in dict:
        for courses in dict[teachers]:
            course_count.append(courses)
    return course_count

def most_courses(dict):
    most_teacher = ''
    max_count = 0
    for teacher, courses in teacher.items():
        if len(courses) > max_count:
            most_teacher = teacher
            max_count = len(courses)
    return most_teacher
Derek McCool
Derek McCool
12,289 Points

I figured it out, the error was misleading.

1 Answer

Huh. You seems to be iterating over the teacher dictionary, although it doesn't exist.

Try iterating over the dict dictionary (the argument passed in).

I hope this helps. ~Alex