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

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