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

I don't understand why my codes isn't accepted in teachers.py 3/3. It outputs the exact required values in a list.

def stats(teachersDictionary):
    teachersLt = []
    classesLt = []
    numberOfClassesLt = []
    statsLt = []
    for teacher in teachersDictionary.keys():
        teachersLt.append(teacher)
        if teacher in teachersDictionary:
            numClasses = len(teachersDictionary.get(teacher))
            classes = teachersDictionary.get(teacher)
            numberOfClassesLt.append(numClasses)
            classesLt.append(classes)
    for i in range(len(teachersLt)):
      statsLt.append(teachersLt[i])
      statsLt.append(numberOfClassesLt[i])
    return statsLt

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

I updated the code challenge to better show you the output that stats() gives. Your code is good except you're not returning a list of lists (one inside list per teacher), you're only returning one list.

Hehe, thank you. I guess I hadn't read the task correctly. I figured it out now. I now use a temporary list for the individual teacher stats and another list for the stats:

def stats2(teachersDictionary):
    teachersLt = []
    classesLt = []
    numberOfClassesLt = []
    statsLt = []
    for teacher in teachersDictionary.keys():
        teachersLt.append(teacher)
        if teacher in teachersDictionary:
            numClasses = len(teachersDictionary.get(teacher))
            classes = teachersDictionary.get(teacher)
            numberOfClassesLt.append(numClasses)
            classesLt.append(classes)
    for i in range(len(teachersLt)):
      tempLt = []
      tempLt.append(teachersLt[i])
      tempLt.append(numberOfClassesLt[i])
      statsLt.append(tempLt)
    return statsLt