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

teachers.py() part 2

I ran this on workspaces and it worked perfectly. It doesn't pass the test however. Any suggestions?

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(dic):
    for teachers in dic:
        teacher_count = len(dic.keys())
    return teacher_count

def num_courses(dic):
    new_list = []
    for teachers in dic:
        value_count = dic.values()
        new_list.extend(value_count)
        list_len = len(new_list)
    return(list_len)

1 Answer

Steven Parker
Steven Parker
231,236 Points

When you say it "worked perfectly", you may have misunderstood the objective. The challenge says, "The function should return the total number of courses for all of the teachers." Note that's "all" and not "each".

So just as "num_teachers" returned a total number, "num_courses" should return a single value with a grand total instead of a list.