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 trialZachary Kaufman
1,463 PointsI'm stuck...
Hi guys, I am really stuck with this Code Challenge, if anyone can help I'd really appreciate it.
# 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(dictionary):
classes = 0
top_teacher = "none"
dictionary = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
'Kenneth Love': ['Python Basics', 'Python Collections']}
for key in dictionary:
if len(dictionary.value()) > classes:
classes = len(dictionary.value())
teacher = dictionary[key]
return teacher
1 Answer
Seth Kroger
56,413 PointsIf you have an argument named dictionary being passed in, you don't have to assign dictionary to something else. That just overwrites the data being passed in.
Zachary Kaufman
1,463 PointsZachary Kaufman
1,463 PointsI'm sorry I don't know what you mean, I can't deleted "dictionary" as an argument for most_classes, but if I delete the dictionary dict from lines 14-15 then it still gives me the same error I had before which is, "Bummer! 'dict' object has no attribute 'value'"
Seth Kroger
56,413 PointsSeth Kroger
56,413 PointsSorry, just saw the obvious error an stopped looking further. I think what you're looking for is the length of the value corresponding to the key so in should be len(dictionary[key]) and given that the the teacher is the key you should have the teacher = key, not dictionary[key] which is the list of courses.
Zachary Kaufman
1,463 PointsZachary Kaufman
1,463 PointsFor which part? I tried that for the if statement, the classes variable, and the teacher variable and it all gave me errors.
Seth Kroger
56,413 PointsSeth Kroger
56,413 PointsZachary Kaufman
1,463 PointsZachary Kaufman
1,463 PointsAh okay I see my problems, thanks for your help!