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

returning dictionary

i can't figure out why my code wouldn't work

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):
    numberOfTeachers=num_teachers.count()
    return numberOfTeachers

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Mathew,

the num_teachers method expects a set as its parameter. You are trying to call count() on your freshly declared methods name and I am not sure you can do it. You need a method that counts the keys of the set and returns this number.

Sadly, a set has no attribute count() that could do it for you. But python does.

You can use the num_teachers parameter teachers as an argument for the len() function. This function will count the keys (how many teachers are in the set) and you can return that number.

I would use this code:

def num_teachers(teachers):
    number_of_teachers = len(teachers)
    return number_of_teachers