Python Python Collections Dictionaries Teacher Stats

Blue Miles
Blue Miles
4,305 Points

Why is the last function incorrect?

this challenge has several steps so take your time, read the instructions carefully, and feel free to experiment in Workspaces or on your own computer. For this first task, create a function named num_teachers that takes a single argument, which will be a dictionary of Treehouse teachers and their courses. The num_teachers function should return an integer for how many teachers are in the dict.

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):
    return len(dictionary.keys())

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

def courses(dictionary):
    av_courses=[]
    for courses in dictionary.values():
        av_courses.extend(courses)
    return av_courses

def most_courses(dictionary):
    max_count = 0
    MVP = ""
    for key, values in dictionary.item():
        if len(values) > max_count:
            max_count= len(values)
            MVP = keys
    return MVP

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 45,225 Points

I tried this in a workspace where you'll receive better error messages. You have two:

AttributeError: 'dict' object has no attribute 'item'

NameError: name 'keys' is not defined

Both can be fixed with an s