Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Dictionaries Teacher Stats

Code works in local environment, does not work in challenge

Attached code for stats function works in my REPL locally, but running in challenge it says "Bummer: Try again"

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

def num_courses(teachers):
    courses = 0
    for teacher in teachers:
        courses += len(teachers[teacher])
    return courses

def courses(teachers):
    course_list = []
    for teacher in teachers:
        course_list.extend(teachers[teacher])
    return course_list

def most_courses(teachers):
    return max(teachers, key = lambda x: len(set(teachers[x])))

def stats(teachers):
    stat_list = []
    for teacher in teachers:
        teacher_list = []
        teacher_list.append(teacher)
        teacher_list.append(len(teachers[teacher]))
        stat_list.append(teacher_list)
    return stat_list

1 Answer

Michael Hulet
Michael Hulet
47,869 Points

Hmm, I just copy/pasted your code into the challenge, and it passed all the steps for me just fine. Perhaps you're having some kind of communication error? Also, you could try clearing your cookies/cache/such and restarting your browser and try again. If none of these work, I'd email support

Hi Michael,

I think there might have been something strange going on with how my code was being cached on the server. I am thinking possibly some kind of timeout period was hit or something? I might have had the window open for some time before returning to the challenge. I clicked restart to restart the challenge from the beginning which wiped out my progress on the server and re-pasted my code in and it succeeded this time. Just thought you might like to know in case there is a bug reporting system you guys have. Might be able to replicate, or it could just be a freak occurrence.

Thanks, Cody

Michael Hulet
Michael Hulet
47,869 Points

I've had weird issues like that before. I don't work for Treehouse (I'm only a volunteer), but either way, it's better if you submit a report yourself so they can get an idea of how widespread the issue is. I'm sure they'd appreciate it if you emailed help@teamtreehouse.com and describe the issue you ran into