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

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.