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

Keep Getting an Unknown Error on code challenge!

With the following code I cannot pass the challenge. I am on step 4 out of 5 (most_courses function) and it keeps spitting out the error, cannot find most_courses! All help is much appreciated!!

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

def num_courses(dictionary):
    count = 0
    for courses in dictionary.values():
        count += len(courses)
    return count

def courses(dic):
    list = []
    for courses in dic.values():
        for stuff in courses:
            list.append(stuff)
    return list

def most_courses(dic):
    max_num_courses = 0
    for key, value in dic.items():
        if len(v) > m_courses:
            m_courses = len(v)
            teacher = k
    return teacher 

1 Answer

if len(v) > m_courses:
            m_courses = len(v)
            teacher = k

You haven't defined v, k, m_courses anywhere. So python has no clue what you mean...