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

challenge task 5 where the hell i did wrong ? can any one explain me please

its ok when i am testing in python shell and even in workspace . but when i submit the challenge the bummer poped up saying"Didn't get the right output" can you guys help me

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.

teachers = {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'], 'Kenneth Love': ['Python Basics', 'Python Collections']}

def num_teachers(teachers):
    num = 0
    for d in teachers.keys():
        num = num + 1
    return num

def num_courses(teachers):
    total = 0
    for v in teachers.values():
        s = len(v)
        total = total + s
    return total

def courses(teachers):
    all_courses =[]
    for v in teachers.values():
        all_courses.extend(v)

    return all_courses

def most_courses(teachers):
    max_count = 0
    name = ""
    for teacher, course_list in teachers.items():
        if len(course_list) > max_count:
            max_count = len(course_list)
            name = teacher
    return name

def stats(teachers):
    list = []
    for teacher, course_list in teachers.items():
        another = [teacher, len(course_list)]
        list.append(another)

        return list

1 Answer

lol sorry guys i found my mistake i just returned list in looping body lol haha ... programming in freaking awesome and headache too ... haha