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

teachers.py

Can anyone help me in the fourth task

Im returning 5 instead of 18

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):
         counts = []
         max_classes = 0 
         for key in teachers:
             counts.append(len(teachers[key]))

         for value in counts:
             if value > max_classes:
                max_classes = value 

         for key in teachers:
             if max_classes == len(teachers[key]):
                return key

def num_teachers(teach_dict):
  teach_count = 0
  for name in teach_dict:
    teach_count += 1
  return teach_count

def stats(teachers):
  total_stats = []
  for teacher in teachers:
    total_stats.append( [teacher, len(teachers[teacher])] )
  return total_stats

def courses(teachers_dict):
  course = []
  for list_of_classes in teachers_dict.values():
    course.extend(teachers_dict.values())
  return course

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Adrian,

You are almost there. The challenge wants a single list of all the courses taught. As you have it right now, you are looping through the dictionary values and creating a list of lists (Remember that list_of_classes is a list, not a single item). You just need to go one step further and pull out the items from each of those lists. For this you can use another nested for loop.

Good luck.