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 trialNikolas Boling
2,403 PointsTeacher Stats challenge 5:5. I don't know why it is giving me a "Didn't get the right output" error.
When I tried this exact code in my own work-space I get what looks to be what the question is asking for. But when I try it in here it doesn't work. My guess is that my formatting is wrong, but I'm not to sure on how it could be wrong. Any help or advice would be great! Thanks.
# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Each key will be a Teacher and the value will be a list of courses.
#
# Your code goes below here.
def num_teachers(dictionary):
count = 0
for teachers in dictionary:
count += 1
return count
def num_courses(dict):
course_list = []
count = 0
for value in dict.values():
course_list.extend(value)
count += len(course_list)
return count
def courses(dict):
course_list = []
for value in dict.values():
course_list.extend(value)
return course_list
def most_courses(dict):
maxNum = 0
name = ''
for teacher,course in dict.items():
if len(course) > maxNum:
name = teacher
maxNum = len(course)
return name
def stats(dict):
teacher_list = []
for teacher,course in dict.items():
new_string = '{},{}'.format(teacher, int(len(course))).split(',')
teacher_list.append(new_string)
return teacher_list
1 Answer
Steven Parker
231,248 PointsBe careful of testing challenges using the workspace.
If you misunderstand the instructions, it's likely you will also misinterpret the results.
The challenge instructions say your function should return " a list of lists", but you're returning a list of strings. So instead of creating a new_string, simply append a two-item list that has the teacher and the count of courses.