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 trialJohnny Evans
996 PointsMy code works in the workspaces console; However, I am getting an error in the challenge task window:
See subject line.
def most_classes(edict):
most = 0
teach = ''
for item in edict:
num = len(edict[item])
if num >= most:
most = num
teach = item
return teach
def num_teachers(edict):
count = 0
for item in edict:
count +=1
return count
def stats(edict):
elist = []
for item in edict:
elist.append([item, len(edict[item])])
1 Answer
jacinator
11,936 PointsThe only thing that you're missing is the return
on stats
. The other thing in my code is that I'm using the dict.items
method and I used the dict.keys
method.
def most_classes(teachers):
final_teacher = None
class_count = 0
for teacher, classes in teachers.items():
if len(classes) > class_count:
final_teacher, class_count = teacher, len(classes)
return final_teacher
def num_teachers(teachers):
return len(teachers.keys()) # This is a better way of doing it.
def stats(teachers):
courses = []
for teacher, classes in teachers.items():
courses.append([teacher, len(classes)])
return courses # The only thing that I can see that you're missing