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 trial
Keith Whatling
17,759 PointsTeacher Stats, code works but wont pass the test? Any ideas.
Hi,
I am trying to pass the updated collections course in Python, I cannot get passed the Teachers Stats at the end of the Dictionary section.
The task: In this last challenge, I want you to create a function named stats and it'll take our teacher dictionary as its only argument. stats should return a list of lists where the first item in each inner list is the teacher's name and the second item is the number of courses that teacher has. For example, it might return: [["Kenneth Love", 5], ["Craig Dennis", 10]]
I get to section five and it tells me that task 4 is no longer passing.
def stats(arg):
to_return = []
for teacher, courses in arg.items():
to_return.append([teacher, len(courses)])
return to_return
and below is the full code.
def num_teachers(arg):
return len(arg)
def num_courses(arg):
return sum([len(courses) for courses in arg.values()])
def courses(arg):
return [course for courses in arg.values() for course in courses]
def most_courses(arg):
maxnum = 0
to_return = ''
for teacher, courses in arg.items():
if len(courses) > maxnum:
to_return = teacher
return to_return
# Task 5
def stats(arg):
to_return = []
for teacher, courses in arg.items():
to_return.append([teacher, len(courses)])
return to_return
Very frustrating! as it works in python ide.
2 Answers
Steven Parker
243,318 PointsYour task 4 code really doesn't pass.
I'm guessing it did once, so you got to task 5, but right now it won't pass. You never update maxnum, so every teacher tested will seem like the one with the most courses, and the function will always return the last one.
Keith Whatling
17,759 PointsWhat a twit. Thanks