Python Python Collections (2016, retired 2019) Dictionaries Teacher Stats

Conner Williams
Conner Williams
Pro Student 3,305 Points

What is the proper way to solve the 5th task?

I have tried quite a few different approaches to the list.append/update line in this code. I am convinced that is where the error lies but, i cannot seem to make it work. Help is much appreciated!
# 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(teachers):
    count = len(teachers.keys())
    return count

def num_courses(teachers):
    number = []
    for value in teachers.values():
        number += value
    return len(number)

def courses(teachers):
    courses = []
    for course in teachers.values():
        courses += course
    return courses

def most_courses(teachers):
    max_count = 0
    teach = " " 
    for teacher,courses in teachers.items():
        if len(courses) > (max_count):
            teacher = teacher
            max_count = len(courses)
    return teacher

def stats(teachers):
    list = []
    for teacher,courses in teachers.items():
        list.append([teachers.keys(), len(teachers.values())])
    return (list) 

1 Answer

Hello there. When you call teachers.items() you don't need to type .keys() or .values() because you already gave them names (teacher & courses).

def stats(teachers):
    list = []
    for teacher,courses in teachers.items():
        list.append([teacher, len(courses)])
    return (list)