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

Frank Hoke
Frank Hoke
8,651 Points

The code makes a list of lists for stats, but ....

I've written code several ways that will make a list of lists that works, but it doesn't like something because it gets rejected, maybe the formatting? Am I missing something obvious?

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_dict):
teachers_dict = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],'Kenneth Love': ['Python Basics', 'Python Collections']}

def most_classes(teachers_dict):

    maxcount = 0
    newcount =0

    for teacher in teachers_dict:

        newcount =len(teachers_dict[teacher])

        if newcount > maxcount:
          maxcount = newcount
          max_teacher = teacher

    return max_teacher

def num_teachers(teachers_dict):

  number = len(teachers_dict.keys())

  return number

def stats(dicts):
    stats_list = []
    for key, value in dicts.items():
      item  = "{},{}".format(key, int(len(value))).split(",")
      stats_list.append(item)
    return stats_list
Frank Hoke
Frank Hoke
8,651 Points

Thanks. Tried that and still get a lists of lists, but it still says "didn't get the expected output". The answer looks like what is being asked for, so I'm unsure why it is being rejected.

Dan Johnson
Dan Johnson
40,533 Points

If you're still having issues with the challenge post your updated code and I'll go over it.

2 Answers

Dan Johnson
Dan Johnson
40,533 Points

With the method you're using, the course count is of type str when a type of int is expected.

Instead of dealing with a str conversion and back, you could go right for the list:

item = [key, len(value)]
Frank Hoke
Frank Hoke
8,651 Points

Found another approach that was accepted as correct: