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

Andrew Bickham
Andrew Bickham
1,461 Points

def stats

could someone point where the problem might be

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.
#
def num_teachers(teachers):
   count = len(teachers.keys())
   return count 



def num_courses(teachers):
    number = []
    for value in teachers.values():
        number += value
    return len(number)




def courses(teachers):
    number = []
    for value in teachers.values():
        number += value
    return number



def most_courses(a):
    teacher = ""
    max_count = 0
    for t,c in a.items():
        if len(c) > max_count:
            teacher = t
            max_count = len(c)
    return teacher

def stats(teachers):
    l = []
    g = []
    k = []
    m = []

    for t in teachers.keys():
        l.append(t)
    for c in teachers.values():
        g.append(len(c))
    part = g.pop(0)
    part2 = g.pop(0)
    k.append(part)
    m.append(part2)
    l.insert(1,k)
    l.insert(3,m)
    print(l)

1 Answer

Steven Parker
Steven Parker
229,732 Points

The challenge wants you to create a "list of lists". So each pair of key (teacher name) and value length should be it's own mini-list, and that list would be appended to the output list. The whole thing should take just a few lines of code.

Also, remember to return the output list. You won't need to "print" anything.