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

dmitriy ignatiev
seal-mask
.a{fill-rule:evenodd;}techdegree
dmitriy ignatiev
Python Web Development Techdegree Student 1,789 Points

Create a function named most_classes

Hi, everyone,

could anybody tell me what i should do next to complete this challenge. I do not want just copy past i want to clarify to myself

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(dicts):

    for teacher in dicts:
        max_count = len(dicts[teacher])

    return max_count

3 Answers

Steven Parker
Steven Parker
229,644 Points

:point_right: The challenge wants to see the teacher's name, not the count.

In your loop, you'll probably want to check each classes length against the current maximum, and update the maximum only when the length is greater. Then, if you update the maximum, also update a variable that holds the teacher's name.

Finally, when the loop ends return the top teacher's name.

create variable count and set it to 0. then check every new number of classes against this variable and assign it to whatever variable will be greater then it.