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 trialotarie
984 PointsThis code looks right but this is the message i am getting: "Where's the most_classes()?"
I think my code looks right. the challenge is to create a function that takes a dictionary of teachers and returns the teacher with the most classes.
# 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(teachers):
max_count = 0
for teacher in teachers:
if len(teacher[key])>max_count:
max_count = len(teacher[key])
new_winner = teacher
return new_winner
2 Answers
Chi-Shiang Wang
3,471 Pointsif len(teacher[key]) > max_count -> if len(teachers[teacher]) > max_count
max_count = len(teacher[key]) -> max_count = len(teachers[teacher])
Eleeza Amin
34,496 PointsPlease use markdown!
otarie
984 PointsThanks, now it works!!
Chi-Shiang Wang
3,471 PointsChi-Shiang Wang
3,471 PointsTry to change your code as follow:
because, the "teacher" in your for-loop is mean "key", if you want to get the values of the key you need use teachers[teacher].
ex: 1st loop "teacher = Jason Seifer" when you use len(teacher) you will get "12" "teachers[teacher] = 'Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'" then use len(teachers[teacher]) you will get "3"
hoping this comment can help you solve your problem. (sorry for my poor english >"<)