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

Kristian Vrgoc
Kristian Vrgoc
3,046 Points

Challenge Teacher 4/5: What if multiple teachers have the same amount of courses...

Hey,

I was practicing in the workspace and realized that if I had multiple teachers with the same amount I would get only one listed in my case "Andrew Chalkey".

So I tried to find a solution here it is

https://w.trhou.se/iqigyo8324

What do you think?

1 Answer

That won't work. If your dictionary has an increasing amount of courses for each entry then all teachers will be included. For example try:

my_dict = {'Andrew Chalkley': ['jQuery Basics'], 'Kenneth Love': ['Python Basics', 'Python Collections'],'Teacher 3': ['Course 1', 'Course 2', 'Course 3']}

Here Andrew has one course, Kenneth two, and Teacher 3 has three. len(courses) is greater than max_count as we proceed through the dictionary so each teacher is appended.

You could go through the dictionary twice. Once to get the max count. Then a second time to append teachers that match the max count.