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

Tommy Seabolt
Tommy Seabolt
22,788 Points

Python Collections Dictionary Bug Task 4: function name in challenge asks for most_classes should be most_courses

The compiler threw an error asking for most_courses.

I changed the function name from most_classes to most_courses and passed the challenge.

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(teach_dict):
    count = 0
    for item in teach_dict:
        count += 1
    return count

def num_courses(teach_dict):
    count = 0
    for arr in teach_dict.values():
        for item in arr:
            count += 1
    return count

def courses(teach_dict):
    courses = []
    for arr in teach_dict.values():
        for item in arr:
            courses.append(item)
    return courses

def most_courses(teach_dict):
    count = 0
    teacher_with_most_classes = ""
    for teacher in teach_dict:
        if len(teach_dict[teacher]) > count:
            count = len(teach_dict[teacher])
            teacher_with_most_classes = teacher
    return teacher_with_most_classes

Agreed!

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

My advice is to report this to Treehouse support. You might even get the coveted bug squasher badge! The instructions do seem to be incorrect. When I change from "most_classes" as required per the challenge to the "most_courses" as indicated by the "Bummer!" message, it does indeed pass.

Tommy Seabolt
Tommy Seabolt
22,788 Points

Thanks for verifying. :) How do I submit it to Treehouse support? I'm loving the Python Track by the way. Can't wait to get to the Flask Rest API tutorials.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

If you click on the Support button at the top of this page, you'll be directed to a page that will tell you how to contact support when issuing a bug report and what kind of information they want. Don't forget to link in this page with this question and answer when you submit it! :sparkles:

Tommy Seabolt
Tommy Seabolt
22,788 Points

Thanks Jennifer! I submitted it seven days ago and customer service was very quick. Apparently someone had submitted before me and it should be fixed now.

High fives and happy New Years! Thanks for your help!

Dalton Dunn
Dalton Dunn
6,709 Points

How did you even come up with that? I tried several different things but that didnt even come to my mind. didnt remember ever seeing that during the videos on this track.

Tommy Seabolt
Tommy Seabolt
22,788 Points

My intro to programming class used Python 3 and that was almost four years ago. And ever since then I've tried to "play" with the language as much as possible.

That being said my intro class never went into sets, dictionaries, lists or tuples. Nor did we ever get to object oriented Python. So I've learned a ton in the Python track on Treehouse.

My approach to problem solving is typically asking/defining the problem at hand. If I find myself struggling to get the solution I'll break the problem down into sub-items and write each sub-item in a comment. Typically as soon as I do that the code essentially "writes itself." If I really get confused I take a break.

Passing the iterable back into the dictionary as a key to get the value is something I had seen outside of Treehouse. You just as easily could have used a key, value pair with .items() method as was demonstrated in the videos.

Hope this helps and Happy New Year's!