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

Christopher Shanor
PLUS
Christopher Shanor
Courses Plus Student 2,537 Points

teachers.py challenge task 3 of 5. Passes the console, but not the challenge. Any ideas?

In the last method, courses, the extend method constructs a new list of the classes. How come it will not pass?

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.
teachers = {"Kenneth Love" : ["Python Basics", "Python Collections"], "Andrew Chalkey": ["JQuery Basics", "Node.js Basics"]}

def num_teachers(teachers):
    return len(teachers)

def num_courses(teachers):
    total = 0
    for i in teachers:
        total += len(teachers[i])
    return total

def courses(teachers):
    courses1 = teachers.get("Kenneth Love")
    courses2 = teachers.get("Andrew Chalkey")
    courses1.extend(courses2)
    return courses1

1 Answer

Steven Parker
Steven Parker
231,007 Points

Don't rely on the sample data shown in the comments.

The actual data used to test your code will be different, and likely more extensive, than the short example given in the comments.

Write your function so that it does not rely on knowing how many teachers will be in the passed-in dictionary, or what their names will be.