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 Dictionary Iteration

code didn't work on Treehouse

My code works on console but in challenge it shows task 1 no longer passing. what might be the problem??

dic={'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
     'Kenneth Love': ['Python Basics', 'Python Collections']}

def most_classes(dic):
  m_c=0

  for k in dic:
    n_c=len(dic[k])
    if n_c > m_c:
      best_teacher=k
  return k

def num_teachers(dic):
  count=0
  for teacher in dic:
    count+=1
  return count

[MOD: added ```python formatting -cf]

Got it. Thanks :)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

In most_classes you are returning k which is the last teacher in the loop instead of best_teacher