Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Emil Hejlesen
Emil Hejlesen
3,014 Points

i don't understand

please help i dont understand this one

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.

dict = {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
        'Kenneth Love': ['Python Basics', 'Python Collections']}

def num_teachers(dict):
    teachers = 0
    for x in dict.keys():
        teachers += 1
    return teachers

def num_courses(dict):
    courses = 0
    for x in dict.values():
        for y in x:
            courses += 1
    return courses

def courses(dict):
    list = []
    for x in dict.values():
        for y in x:
            list.append(y)
    return list

def most_courses(teacher ):

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,363 Points

Hi Emil, check this one out:

def most_courses(dict):
    high = 0 # needed to store the number of courses and use it for comparison
    for teacher in dict:
        if len(dict[teacher]) > high: # if the number of courses exseed the previous number
            boss = [] # always start with a fresh list, previous teachers names are removed
            boss.append(teacher) # append the name
    return "".join(boss) # join the list containing the name of the boss teacher to a string

Makes sense?

Emil Hejlesen
Emil Hejlesen
3,014 Points

yes it does thank you so much :)