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!

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

Ralph Hellstern
Ralph Hellstern
6,106 Points

Question 3 of 5

Hi, I am stuck with question 3 of 5. What is wrong with my code? Thanks in advance.

# 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):
    counter = 0
    for value in dict.values():
        counter += len(value)
    return counter

def courses(dict):
    list = []
    for value in dict.values():
        list = dict.extend(value)
    return list

1 Answer

Josh Keenan
Josh Keenan
19,652 Points

Here's my solution, it uses a for loop to iterate over the values (courses) each teacher has, then for each list of courses it starts a new for loop, to go through the list of their courses and then appends them to the course_list

def courses(arg):
    course_list = []
    for value in arg.values():
        for i in value:
    return course_list