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 trialjohn larson
16,594 PointsI have an answer that passes this challenge, but I'm wondering...
What would the code look like If we only used stuff that was taught so far in this course. Or is that not even the point. I think I get that the "gotcha" for this one is that we can't use lists to store teachers because the number of teachers would change.
- here is the code I'm going with
teachers_dict = {
'Jason Seifer': [
'Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
'Kenneth Love': [
'Python Basics', 'Python Collections']
}
def most_classes(teachers):
final_teacher = None
class_count = 0
for teacher, classes in teachers.items():
if len(classes) > class_count:
final_teacher = teacher
class_count = len(classes)
return final_teacher
x = most_classes(teachers_dict)
print(x)
john larson
16,594 PointsHi Jason, thanks for responding. It took some digging but I found one. Apparently most people didn't struggle with this part of the challenge like I did. This is the one I found that I'm going to comb over and see what makes it tick.
max_count = 0
max_teacher = ''
for key in teachers:
class_count = len(teachers[key])
if class_count > max_count:
max_teacher = key
max_count = class_count
return max_teacher
2 Answers
Aer sdfsd
1,669 Pointsi have pretty much the same code as yours, it works fine in shell. but here it does not pass.
def most_classes(dic):
count = 0
name = ""
for i in dic:
num = len(dic[i])
if num > count:
count = num
name = i
return i
Jason Anello
Courses Plus Student 94,610 PointsYou're returning i
which is the last teacher you looked at. Try returning name
instead.
Aer sdfsd
1,669 Pointsyeah. I have figured that out already aftery looking through the code for 100th time) thanks.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi John,
I don't remember exactly what you've been taught up to this point but if you want to point out anything you think you weren't taught yet then I can try to rewrite it for you more in line with what you've been taught.
Maybe the .items() method wasn't covered yet but that's all I'm really seeing.