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

victor E
victor E
19,146 Points

need help on this one too :(

whats wrong with my code!?

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(dictionary):
    return len(dictionary)

def num_courses(dictionary):
    counter = 0
    for value in dictionary.values():
        counter += len(value)
    return counter
def courses(dictionary):
    library = []
    for items in dictionary.values():
        library.extend(items)
    return library 
def most_courses(teachers):
    max = 0
    teacher = ""
    for key, value in teachers.items():
        if len(value) > max:
            max = len(value)
            teacher = key
    return teacher

def stats(dictionary):
    for key, in dictionary:
        new =  key, len(value)
    return list(new)

1 Answer

Here's what I did.

def stats(dictionary):
    new = []
    for key, value in dictionary.items():
        new.append([key, len(value)])
    return new
victor E
victor E
19,146 Points

beautiful!! thanks!!