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

Carl Larsen
Carl Larsen
1,061 Points

Returning a list of all the single courses in teachers (Dictionaries)

Prompt: "For this step, make another new function named courses that will, again, take the dictionary of teachers and courses. 'courses', though, should return a single list of all of the available courses in the dictionary. No teachers, just course names!"

Attached is my attempt at this problem which does not work. Any help in solving this step (3) would be much appreciated.

Thanks in Advance, Carl

# 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):
    count = 0
    for teacher in teachers:
        count += 1
    return count

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

def courses (teachers)
    return teachers.values()

def courses(teachers):
    out = []
    for teacher in teachers:
    return out

2 Answers

Steven Parker
Steven Parker
230,230 Points

There should be only one function named "courses", but there's two here and the first one is not correct.

Just remove the first one and you should pass task 3.

Carl Larsen
Carl Larsen
1,061 Points

Splendid, Thanks for the help :)