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

How can I return a list of all values from a dictionary??

I need to create a function that accepts a dict and returns a list of all the course values in a list, (ps the third method)

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

def num_courses(dict):
    course_count = 0
    for course in dict.values():
        course_count += len(course)
    return course_count

def courses(dict):
    course_list = []
    for course in dict.values():
        course_list.append(course)
    return course_list

2 Answers

I think your problem might be with using .append(). You will end up adding a list to the list, and the challenge wants one single list. I tried your code as-is, subbing only a different method call for .append(), and it worked. I hope that helps.

thanks I used extend() which makes sense lol, once again appreciate the help