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

alex albas
seal-mask
.a{fill-rule:evenodd;}techdegree
alex albas
Front End Web Development Techdegree Student 2,190 Points

Problems with this challenge..

I can't find where is the error here..some help is appreciated!

<script src="http://pastebin.com/embed_js.php?i=J70iJTRV"></script>

<iframe src="http://pastebin.com/embed_iframe.php?i=J70iJTRV" style="border:none;width:100%"></iframe>

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(teacher_dict):
  max_count = 0
  count  = 0
  for teacher in teacher_dict:
    for item in teacher:
      count+=1
    if count > max_count:
      max_count = count
      teach= teacher
    count = 0
return teach

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points
  • the return statement at the very last line is at the same indentation level of def most_classes(teacher_dict):, this makes it outside of function definition body.
  • you really don't need a nested for loop, make use of len() instead.
def most_classes(teacher_dict):
  max_count = 0
  count  = 0
  for teacher in teacher_dict:
    count = len(teacher_dict[teacher])
    if count > max_count:
      max_count = count
      teach = teacher
    count = 0
  return teach