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

Write a function named courses that takes the dictionary of teachers. It should return a list of all of the courses

I have no clue what is wrong with my code. I'm sure it is another stupid misunderstanding of what the challenge is asking for. I wish we had access to the test data the course is using. It would make it a lot easier to figure out the problem.

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(teachers):
  max_count = 0
  max_teach = ''
  for teacher in teachers:
    if len(teachers[teacher]) > max_count:
      max_count = len(teachers[teacher])
      max_teach = teacher
  return max_teach

def num_teachers(teachers):
  return len(teachers)

def stats(teachers):
  stats_list = list()
  temp_list = list()
  for key in teachers:
    temp_list.append(key)
    temp_list.append(len(teachers[key]))
    stats_list.append(temp_list)
    temp_list = list()
  return stats_list


def courses(teachers):
  new_list = list()
  for key in teachers:
    new_list.append(teachers[key])
  return new_list

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi Deborah,

Here is my (hopefully) self-documented example, which I have added comments to.

def courses(teachers): # definition for courses function
  course_output = []    # output currently empty... we will populate it soon.
  for course_total in teachers.values(): # for all of the values in teachers...
    for course in course_total: # for all of the values in the total of courses...
      course_output.append(course) # populate our empty output variable.
  return course_output # return the output variable, now that it is populated.

Actually, I just needed to change my append to extend and my code worked fine. Thanks for your answer.