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

Dict inquiry on 5 step quiz

not sure where i am going wrong. please take a look.

def num_teachers(teachers_courses): return len(teachers_courses)

def num_courses(teachers_courses): return sum(len(v) for v in teachers_courses.values())

def courses(teachers_courses): single_list = [] for courses in teachers_courses.values(): single_list += courses

return single_list
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(teachers_courses):
    return len(teachers_courses)

def num_courses(teachers_courses):
    return sum(len(v) for v in teachers_courses.values())

def courses(teachers_courses):
    single_list = []
    for single_list in teachers_courses.values():
        single_list += courses
    return single_list

1 Answer

i got it!

def num_teachers(teachers_courses):
    return len(teachers_courses)

def num_courses(teachers_courses):
    return sum(len(v) for v in teachers_courses.values())

def courses(teachers_courses):
    single_list = []
    for courses in teachers_courses.values():
        for course in total_course:
            single_list.extend(course)

    return single_list

Great! I'm at the exact same place as you btw :)

Herman Brummer
Herman Brummer
6,414 Points
def courses(dictionary_list):
    # list of all the courses
    all_courses = []
    for courses in dictionary_list.values():
        all_courses = all_courses + courses
    return all_courses