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 trialSean Manners
14,816 PointsTeacher Stats.. 3 / 4. No Longer Passing Task 1?
Okay. So I made a solid effort at not browsing the community for this one, but I do see alot of answers that would work. My issue is that I don't want to rewrite the code to be another person's solution, but rather force this one to work.
I've seen that most of the community did the num_teachers function differently than me. Is it possible that that's causing my code to fail? When I revert to Task 1, it passes with no issues, so I'm assuming that something I wrote in the stats function is causing my most_classes function to fail.
That said, I can't figure out what.
Please help!
# 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):
max_count = 0
most_class = ""
for teacher in dictionary:
if len(dictionary[teacher]) > max_count:
max_count = len(dictionary[teacher])
most_class = teacher
return most_class
def num_teachers(dictionary):
teach_num = len(dictionary.keys())
return teach_num
def stats(dictionary):
new_list = []
for teacher in dictionary:
new_string = [teacher, len([dictionary[teacher])]
new_list.append(new_string)
return new_list
1 Answer
Sean Manners
14,816 PointsScratch that!
Fixed my syntax, had one too many brackets in my Stats Function!
Thanks anyway!
:D