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

returning name of the teacher with the most number of courses

am trying task on python collections which need to iterate through the dictionary and return the name of the teacher with the highest number of courses

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(tutors):
    count = len(tutors.keys())
    return count

def num_courses(tutors):
    count = 0
    course_list = []
    for name in tutors.keys():
        for course in tutors[name]:
            if course not in course_list:
                course_list.append(course)
    return len(course_list)

def courses(tutors):
    avail_courses = []
    for courses in tutors.values():
        avail_courses.extend(courses)

    return avail_courses

def most_courses(tutors):
    course_count = 0
    teacher_name = ''
    for name, courses in tutors.items():
        lf len(courses) > course_count:
            course_count = len(courses)
            teacher_name = name
        else:
            continue
    return teacher_name

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Clainos,

You have a one-character typo in your most_courses function. Where you meant to type if you actually typed lf.

Cheers

Alex