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 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 67,989 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.