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

Josh Keenan
Josh Keenan
20,315 Points

This works but apparently gives the wrong output, help. Dictionaries.

Runs as expected but when I check work it says it gets the wrong output and I have tested the function, someone save me.

teachers.py
# The dictionary will be something like:
# {Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}'Jason 
#
# 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(teachers):
  max_count = 0
  new_winner = ''
  for teacher in teachers:
    print (len(teacher))
    if len(teacher)>max_count:
      max_count = len(teachers[teacher])      
      print("{} {}".format(teacher, max_count))
      new_winner = teacher
  return new_winner


def num_teachers(dicts):
  count = 0
  for key in dicts:
    count += 1
  return count


def stats(mydict):
  list1 = []
  for key, value in mydict.items():
    list1.append([key.title(), len(value)])
  return list1

1 Answer

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

I found 2 errors in your code. Let me know if this helped :)

def most_classes(teachers):
  max_count = 0
  new_winner = ''
  for teacher in teachers:
    print (len(teacher))
    if len(teachers[teacher])>max_count:   #Here I modified len(teacher) for len(teachers[teacher])
      max_count = len(teachers[teacher])      
      print("{} {}".format(teacher, max_count))
      new_winner = teacher
  return new_winner


def num_teachers(dicts):
  count = 0
  for key in dicts:
    count += 1
  return count

def stats(mydict):
  list1 = []
  for key, value in mydict.items():
    list1.append([key, len(value)])   #Here I modified key.title() for key
  return list1