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

For me it should be correct. Can anyone tell me why it is wrong?

Help please

# 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(dict):
    teachers = dict.keys()
    return len(teachers)

def num_courses(dict):
    courses = dict.values()
    for sublist in courses:
        for course in sublist:
            flat_list = []

    return len(flat_list)

1 Answer

Steven Parker
Steven Parker
220,477 Points

The code shown above sets "flat_list" to be empty for each course before adding that course to it, so it will never contain more than one item.

Perhaps you intended to do this initialization only once at the beginning of the function?

Oh, you're right. Thanks man.