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

Tomasz Necek
PLUS
Tomasz Necek
Courses Plus Student 7,028 Points

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

I'm lost, can you help me, thank you

teachers.py
def most_classes(dicts):
  most_class = ""     
  max_count = 0       
  for teacher in dicts:
    if len(dicts[teacher]) > max_count:
      max_count = len(dicts[teacher])
      most_class = teacher
  return most_class
def num_teachers(teacher):
        print(teacher)

2 Answers

Tomasz Necek
PLUS
Tomasz Necek
Courses Plus Student 7,028 Points

why these tasks cannot JUST check the basic knowledge ? JUST about creating the dictionary etc. Not writing the whole program. It shouldn't be for begginers .

Anyone can help?

your dict name is different from Jason

try this one

def most_classes(dicts):
  most_class = ""     
  max_count = 0       
  for teacher in dicts:
    if len(dicts[teacher]) > max_count:
      max_count = len(dicts[teacher])
      most_classes = teacher
  return most_classes

def num_teachers(dicts):
    return len(dicts)

Hi Tomasz,

The num_teachers function can be written in one line and it's going to be a return statement, not a print statement.

As a hint, the length of a dictionary is the number of keys it has.

You only have to use the len() function which you have already used in the previous most_classes function.

A dictionary is going to be passed into your function and each key in that dictionary is a teacher. So getting the number of teachers is the same as getting the number of keys. Getting the length of the dictionary will give you the number of keys it has.

def num_teachers(teacher_dict):
  return len(teacher_dict)