Python Python Collections Dictionaries Teacher Stats

Clainos Machemedze
Clainos Machemedze
951 Points

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
Alex Koumparos
Python Web Development Techdegree Student 23,987 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