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 (Retired) Dictionaries Teacher Stats

To me this looks like it returns Jason Siefer, but the challenge says otherwise

Please show me where I am wrong.

def most_classes(teachers_dict):
    jason = []
    kenneth = []
    for key in teachers_dict:
        if key == "Jason Seifer":
            for course in teachers_dict[key]:
                jason.append(course)
        else:
            for course in teachers_dict[key]:
                kenneth.append(course)


    if len(jason) > len(kenneth):
        return "Jason Seifer"
    else:
        return "Kenneth Love"

1 Answer

Hi John,

I think that you are still making an assumption about the dictionary that is going to be passed in. You're assuming that Jason and Kenneth are the only teachers in this dictionary.

If your code was tested with the example dictionary then it would be correct. But the challenge tester is passing a different dictionary with more teachers in it.

Your else block executes when the teacher is not Jason Seifer. This means that all the courses for all the other teachers are being added to Kenneth's list. This could potentially make Kenneth's list really long as compared to Jason's and so it returns "Kenneth Love"

I think someone had given you the correct code on a previous question you asked about this. I would recommend that you study that code and ask questions on anything you don't understand about it.

Thanks Jason I will study the other code. Part of my learning process is to realize why what I tried didn't work. You explained that perfectly.

That's a good attitude to have.