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

Gregory Heard
Gregory Heard
1,975 Points

I am having a mental block on this one. Can someone help?

I can't think about the process for some reason Any help is appreciated.

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 (lessons):
  count = 0
  for lesson in lessons.values():
    count += 1
    if count == lessons:
      return(lessons[i])

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

A few suggestions. Instead of lesson and lessons use teacher and teachers. Before the loop initialize to 0 two variable: one for the current count and one for the max count. Then loop through the teachers and for the current teacher in the loop find the number of classes he/she teaches. Assign this number to current_count. Now, use an if statement to see if current_count is larger than max_count. If it is update max_count and also hold on to that teacher in a variable, say max_teacher. Once you're done with the loop return max_teacher.