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 (2016, retired 2019) Dictionaries Teacher Stats

Chotipat Metreethummaporn
Chotipat Metreethummaporn
1,129 Points

What wrong with my code? I think it works really fine, but I still got Bummer. (Task 4) --> (most_courses)

  • I am new with this language, but I never give up! -

I really appreciate if someone hints me how to do with task 4.

Thank you very much!

teachers.py
# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Each key will be a Teacher and the value will be a list of courses.
#
# Your code goes below here.


def num_teachers(dictionary):
    length_dict = len(dictionary)
    return length_dict

def num_courses(dictionary):
    number = 0 
    for key in dictionary:
        lists = dictionary["{}".format(key)]
        real = len(lists)
        number += real
    print(number)
    return number

def courses(dictionary):
    result = []
    for key in dictionary:
        lists = dictionary["{}".format(key)]
        result.extend(lists)
        print(result)
    return result

def most_courses(dictionary):
    teacher = ''
    max_count = 0
    for key in dictionary:
        lists = dictionary["{}".format(key)]
        for value in lists:
            compare_count = len(value)
            if compare_count > max_count:
                max_count = compare_count
                teacher = key

    return teacher

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

You are counting the length of each item in the list. This is the length of the course name.

Remove the in for loop, and compare the length of the courses lists. Hint: replace len(value) with len(lists)

Post back if you need more help. Good luck!

Chotipat Metreethummaporn
Chotipat Metreethummaporn
1,129 Points

Oh! I just a little bit of mistake, alright! I can pass the test right now! Thank you very much.