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

Paul Melos
Paul Melos
3,905 Points

teachers.py... What an I doing wrong???

I wish treehouse gave more verbose feedback, I tried the courses function in my terminal and it seemed to work fine. What am I missing?


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!

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(x):
    return len(x.keys())

def num_courses(x):
    total = 0
    for k in x:
        total += len(x[k])
    return total

def courses(x):
    all_courses = []
    for k in x.values():
        all_courses += k
    return all_courses         

1 Answer

Philip Schultz
Philip Schultz
11,437 Points

Your code worked for me when I tried it. This has happened to me a couple times also, I contacted support about it and this was their response.

"Can you please try the following to see if this helps?

If you are using Internet Explorer or Safari, please switch to Google Chrome or Mozilla Firefox. If you're already using Chrome or Firefox and you are still experiencing this issue, please disable your plugins. You can do this temporarily by opening a new window up in Incognito Mode (Chrome) or Safe Mode (Firefox). If a Code Challenge works within one of those two disabled plugin windows then the problem is a plugin on your browser that you'll need to remove."