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

Eran Artzi
Eran Artzi
4,280 Points

I am receiving this error for my code: unorderable types: int() > list() since I am comparing two ints

def most_classes(teach_dict):
    max = 0
    teacher_name = ''
    for teacher in teach_dict:
        if len(teach_dict[teacher]) > max:
            max = teach_dict[teacher]
            teacher_name = teacher
    return teacher_name

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Eran;

You are close. The error you are getting comes from max = teach_dict[teacher]. The first time through the for loop, max is of type int so it doesn't pose an issue. Then you assign max to a list and the second time through the loop you are attempting to evaluate an int() to a list(). We should be comparing the length of both lists, right? Therefore doing something like:

max = len(teach_dict[teacher])

may be appropriate.

Post back if you are still stuck or have further questions.

Happy coding,
Ken

Eran Artzi
Eran Artzi
4,280 Points

Hey Ken,

I tried to go around this by making this alteration:

def most_classes(teach_dict):
    max = 0
    teacher_name = ''
    for teacher in teach_dict:
        if int(len(teach_dict[teacher])) > max:
            max = teach_dict[teacher]
            teacher_name = teacher
    return teacher_name

but I keep getting the same error

Eran Artzi
Eran Artzi
4,280 Points

Oh oh oh....got it,

Thanks!

I think that's a good error to have, a good point to learn :)

thanks,

Eran