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

Sean Clayton
PLUS
Sean Clayton
Courses Plus Student 1,029 Points

Can't see where my code has gone wrong, "Didn't get the right amount of teachers" error

I've been banging my head against this for an hour. Spent some time looking on google and get no actual code errors in workspace, I just can't get it to pass the checks - help would be appreciated!

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(teachers):
    teachers = {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
                'Kenneth Love': ['Python Basics', 'Python Collections']         
               }
    total_teachers = list(teachers.keys())

    return(len(total_teachers))

2 Answers

You don't need to specify the dictionary yourself. The code checker will pass that in as teachers.

Sean Clayton
Sean Clayton
Courses Plus Student 1,029 Points

Perfect, thanks! Didn't even think I could have done too much to pass it. Thanks for the help!

Hey Sean,

First, the function should be able to take any dictionary of teachers -- so take out the dictionary you put inside it.

Second, you can get the length of a dictionary with len(). No need to get the keys first.