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

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