Python Python Collections Dictionaries Teacher Stats

Eli Wickemeier
Eli Wickemeier
1,671 Points

teachers.py task 4

I'm completely stuck on most_courses. I've been able to solve other tasks by reviewing others answers, but I don't feel I'm learning properly that way. It's more copying than learning. Can someone guide me here without completely giving the answer? I know my code gives the values, but I can't figure out how to bring in the keys(teachers).

teachers.py
# The dictionary will look something like:
treehouse = {'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(treehouse):
    return len(treehouse)

def num_courses(treehouse):
    count = 0
    for value in treehouse.values():
        for item in value:
            count += 1
    return count

def courses(treehouse):
    my_list = []
    for value in treehouse.values():
        for value in value:
            my_list.append(value)
    return my_list

 def most_courses(treehouse):
    max_count = 0
    for value in treehouse.values():
        if len(value) > max_count

1 Answer

Rod MIky
Rod MIky
11,356 Points

hey, i think you are doing fine. Everyone feels like they are not learning. Remember programming is not something you can learn in a matter of days. You need to practice, practice more, and keep practicing. Eventually, it will make sense. If you are reading other people's code, try to understand the logic.