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

Python Python Collections (Retired) Dictionaries Teacher Stats

Mr Sri
Mr Sri
9,200 Points

I am getting the error: "Bummer! your returned 5 courses when it should return 18"

I can't seem to figure out what I am doing wrong.

teachers.py
# 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(teacher_dict):
  big_num = 0
  big_teacher = ''
  for teacher in teacher_dict:
    class_num = len(teacher_dict[teacher])
    if (class_num > big_num):
      big_num = class_num
      big_teacher = teacher
  return big_teacher

def num_teachers(teacher_dict):
  total_teachers = 0
  for key in teacher_dict:
    total_teachers += 1
  return total_teachers

def stats(teacher_dict):
  teacher_list = []
  for key in teacher_dict:
    my_list = []
    my_list.append(key)
    my_list.append(len(teacher_dict[key]))
    teacher_list.append(my_list)
  return teacher_list

def courses(teachers):
    output = []
    for courses in teachers.values():
        output.append(courses)
    return output

2 Answers

Boris Ivan Barreto
Boris Ivan Barreto
6,838 Points

Hello,

In the courses function you should use extend instead of append