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 (2016, retired 2019) Dictionaries Teacher Stats

Gilbert Craig
Gilbert Craig
2,102 Points

challenge 5 .. doing something silly

Bummer says stats function not found ...

Cant see why .. any help appreciated

teachers.py
# 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(a_dict):
    num=0
    for teacher in a_dict:
        num += 1
    return num

def num_courses(teachers):
    return sum(len(v) for v in teachers.values())

def courses(a_dict):
    course_list = []
    for teachers in a_dict:
        for courses in a_dict[teachers]:
            course_list.append(courses)
    return course_list

def most_courses(a_dict):
  top_num = 0
  top_teacher = ''
  for teacher in a_dict:
      class_num = len(a_dict[teacher])
      if (class_num > top_num):
          top_num = class_num
          top_teacher = teacher
  return top_teacher

def stats(a_dict):
    i_list = []
    lof_lists = []
    for id in a_dict:
        i_list.append(key)
        i_list.append(len(a_dict[key]))
        lof_list.append(i_list)
    return lof_lists

1 Answer

Gilbert Craig
Gilbert Craig
2,102 Points

Yes, I was .. (a) Missing i_list = [] before the 'return' (b) in the line before I had lof_list instead of lof_lists

All working now .. no answers required.