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

alex albas
alex albas
Front End Web Development Techdegree Student 2,190 Points

i'm getting stuck with courses function...

I don't know why it fails..some help is appreciated :)

# 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):
  max_count = 0
  count  = 0
  for teacher in teacher_dict:
    count = len(teacher_dict[teacher])
    if count > max_count:
      max_count = count
      teach= teacher
    count = 0
  return teach
def num_teachers(teacher_dict):
  count = 0
  for teachers in teacher_dict:
    count += 1
  return count
def stats (teacher_dict):
  teach_list = []
  lista =[]
  for teacher in teacher_dict:
    lista = [teacher,len(teacher_dict[teacher])]
  return teach_list

def courses (teacher_dict):
  i = 0
  for teacher in teacher_dict.values():
      lenght = len(teacher_dict[teacher])
      while i < lenght:
      i = 0
  return lista

2 Answers

William Li
William Li
Courses Plus Student 26,868 Points

You're trying to do too much here, you don't need the i variable or the while loop within the for loop, this problem is asking for

It should return a list of all of the courses offered by all of the teachers.

So all you need to do is just add all courses to the lista list.

you code can be simplified to this.

def courses (teacher_dict):
  for teacher in teacher_dict.values():
    lista += teacher
  return lista