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

J Walker
J Walker
3,854 Points

I suspect that there's something wrong with the site; code not passing. most_courses task 4/5

Hi everyone, I've been stuck on this task for hours. My code is identical to other people's that supposedly passed. I even copy and pasted a good few answers just to see what would happen, but it's still Bummer: Try again!

It actually passed with someone's code (that I wasn't fond of) earlier but I re-started the task and now that same code isn't even working.

Anyways, this is mine which I think is correct.. Or is it? Any help would be great :)

def most_courses(my_dict):
    maxcount = 0
    winning = "" 
    for teacher, courses in my_dict.items():
        if len(courses) > maxcount:
            maxcount = len(courses)
            winning = teacher
    return winning

1 Answer

Dave Harker
PLUS
Dave Harker
Courses Plus Student 15,510 Points

Hi J Walker,

If that code isn't passing I'm not sure why either ... So I quickly just ran through the challenge with the code below ...

def num_teachers(dictionary):
    return len(dictionary)

def num_courses(dictionary):
    total_courses = 0

    for courses in dictionary.values():
        total_courses += len(courses)

    return total_courses

def courses(dictionary):
    course_list = []

    for courses in dictionary.values():
        course_list.extend(courses)

    return course_list

def most_courses(dictionary):
    max_count = 0
    busiest_teacher = ""

    for teacher, courses in dictionary.items():
        if len(courses) > max_count:
            max_count = len(courses)
            busiest_teacher = teacher

    return busiest_teacher

def stats(dictionary):
    quick_list = []

    for teacher, courses in dictionary.items():
        quick_list.append([teacher, len(courses)])

    return quick_list

and you'll note that my challenge #4 answer is the same as you have

Maybe it was just a glitch as those answers all went through fine - first check
Out of curiosity I ran the challenge a second time and again they all passed

So yeah, strange.

Nice work by the way ... keep on coding! :smile:
Dave :dizzy:

J Walker
J Walker
3,854 Points

Thanks Dave! Thought I was going crazy for a minute there ;)