Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Eli Wickemeier
Eli Wickemeier
2,242 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

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.