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

Trevor McGill
Trevor McGill
1,409 Points

Help with counting courses

I'm trying to differentiate between the keys/values when doing the num_courses function, but I can't get it to count the courses alone. I know that my return statement is off...just trying to figure out a way to count the 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(dictionary):
    return len(dictionary)

def num_courses(dictionary):
    return {num_teachers(dictionary.keys()): len(course) for course in dictionary.values()}

1 Answer

Antonio De Rose
Antonio De Rose
20,858 Points
def num_courses(dictionary):
    return {num_teachers(dictionary.keys()): len(course) for course in dictionary.values()}

# few mistakes
# return why is it followed by a curly
# can you try break your code line after line
# does not matter if it wrong, post it back, and I can help you.