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 (Retired) Dictionaries Teacher Stats

Alexander Torres
Alexander Torres
4,486 Points

Next, create a function named num_teachers that takes the same dictionary of teachers and classes. Return the total numb

Why is it telling me my function can not be defined? Down below is my code

teachers = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'], 'Kenneth Love': ['Python Basics', 'Python Collections']}

def num_teachers(teachers): return len(teachers.keys())

teachers.py
teachers = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'], 'Kenneth Love': ['Python Basics', 'Python Collections']}

def most_classes(teachers):
  max_count = {}  

  if (teachers['Jason Seifer']) > (teachers['Kenneth Love']):
    max_count = {'Jason Seifer'}
  else:
    max_count = {'Kenneth Love'}

  for teacher in max_count:
    return teacher

  def num_teachers(teachers):
    return len(teachers.keys())

1 Answer

Josh Keenan
Josh Keenan
19,652 Points

That is an example dictionary, they use other ones too when they test the code, you have created a function that works for that dictionary. But you need one that can be applied to any dictionary of teachers and return the teacher with the most classes, make a more generic version of the function! Forums are here if you need help if you still don't get it!

Alexander Torres
Alexander Torres
4,486 Points

Thanks Josh! I'll get to it