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

My IDLE shell is showing correct but the treehouse shell is not.

Is this code correct?

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):
  most = 0
  best_teacher = ""
  for key in dictionary:
    current = 0
    for values in key:
      current += 1
    if current > most:
      most = current
      best_teacher = key
  return best_teacher

2 Answers

I am struggling with the same task right now. So I can't guarantee my answer is right. But when you say "for values in key" I don't think you are actually looping over the values. To do that, you need to say "for values in dictionary.values():"

If your project is not working, I'd start there.

I put your code into Notepad++ to check it out and no, it does not work. I noticed another thing. Where you put in current += 1, I don't think that's right. What I would change it to is for value in dictionary.values(): current = len(value)

All of the values are lists, see? So to get the length of the list, you can use the len function and save that as the "most" variable. I'm still working through your code and mine. If I find anything else I can tell you about, I will.