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!

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

Quick question over about my code (dictionaries)

I can't seem to get this to work as it is - would I be better off always using a for loop in these type of situations?

def most_classes(my_dict):
    values = list(my_dict.values())
    my_idex = values.index(max(values))
    myKey = list(my_dict.keys())
    return myKey[my_idex]

Yes, use for loop to iterate over keys in dictionary which I name key as teacher. for teacher in my_dict:

1 Answer

Stephen Link
Stephen Link
3,685 Points

What you have would be fine as it is for a simple dictionary where each key has a single integer value. However, the problem indicates that your dictionary is going to be more complicated than that. Each teacher will have a list of classes that they teach and you'll need to determine how many classes a teacher teaches based on that list.