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

it returns a list of teachers with the number of classes but it is saying it is wrong. Not sure what to change

Third challenge. It is returning correctly but it the prompt said it didn't get what was expected.

teachers.py
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.
def most_classes(dictionary):
  max_count=0
  most_classes = {}
  for key,value in dictionary.items():
    teacher_value = len(value)
    if teacher_value > max_count:
      most_classes = key   
      max_count = teacher_value
  return(most_classes)

def num_teachers(dictionary):
  teacher = 0
  for key in dictionary:
    teacher+=1
  return(teacher)

def stats(dictionary):
  stuff = []
  for key, value in dictionary.items():
    piece = "{}, {}".format(key,len(value))
    piece = piece.split(",")
    stuff.append(piece)
  return(stuff)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are very close but the count value is returning as a string instead of as an integer. Changing your stats() function slightly:

def stats(dictionary):
  stuff = []
  for key, value in dictionary.items():
    #piece = "{}, {}".format(key,len(value))
    #piece = piece.split(",")
    piece = [key, len(value)] #<-- create list with teacher name and integer count
    stuff.append(piece)
  return(stuff)

On to Task 4! Good Luck!