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

Owen Wherry
Owen Wherry
1,086 Points

The fourth question of this code challenge works in workspaces but not in the code challenge... what's wrong?

I realize that this code is a bit clunky, but I still don't understand why it won't work in the code challenge. I would highly appreciate it if someone knew what I am doing wrong.

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)

def num_courses(dictionary):
    num = 0
    for value in dictionary.values():
        num += len(value)
    return num

def courses(dictionary):
    courses = []
    for value in dictionary.values():
        courses += value
    return courses

def most_courses(dictdef most_courses(dictionary):
    new_courses = {n: len(dictionary[n]) for n in dictionary.keys()}
    return list(new_courses.keys())[list(new_courses.values()).index(max(new_courses.values()))]

1 Answer

Steven Parker
Steven Parker
171,342 Points

You say this works in the workspace? Those last 3 lines don't look at all like Python syntax to me, the "def" line doesn't even have balanced parentheses. Look closely, maybe something didn't get pasted right.

Owen Wherry
Owen Wherry
1,086 Points

def most_courses(dictionary): new_courses = {n: len(dictionary[n]) for n in dictionary.keys()} return list(new_courses.values()).index(max(new_courses.values()))]

This code worked great! You're right, the "def" line did not get printed right. Thanks!