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

Adam Tyler
Adam Tyler
14,865 Points

Teachers

For challenge 5 I have been asked to create a function called stats which crates a list of lists each containing the teachers and the number of courses they teach, my function seems to work in workspaces doing exactly as asked but in the challenge I get the message "could not find 'stats'" Have I made a stupid error here? Thank you in advance for any help

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

def num_courses(arg):
    x = 0
    for course in arg:
        x += len(arg[course])
    return(x)

def courses(arg):
    list_ = []
    for value in arg.values():
        list_ += value
    return(list_)

def most_courses(arg):
    list_nums = []
    list_keys = []

    for key in arg:
        list_nums.append(len(arg[key]))
        list_keys.append(key)

    return(list_keys[(list_nums.index(max(list_nums)))])

def stats(arg):
    stats_list = []

    for key in dict_:
        stats_list.append([key]+[len(arg[key])])

    return(stats_list)

1 Answer

Ari Misha
Ari Misha
19,323 Points

Hiya Adam! You literally are very very close. Just replace "dict_" with "arg", and you are good to go. (:

Adam Tyler
Adam Tyler
14,865 Points

Argh obviously, thank you I'm such an idiot!!