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

Most_courses, Treehouse Code Challenge. Task 4 of 5 in teachers.py

Can somebody look over my last function labeled "most_courses". Im not sure where I stopped making sense. Thank you peeps

# 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(dict):
    for teachers in dict:
    return num_teachz

def num_courses(The_D):
    for teachers in The_D:
        num_coursies+= len(The_D[teachers])
    return num_coursies

def courses(The_D):
    A_List = []
    for teachers in The_D:
        A_List += The_D[teachers]
    return A_List

def most_courses(The_D):
    for teacher, courses in The_D.items():
        if len(courses)>(MAX_COUNT):
    return WINNNER

4 Answers

Eric M
Eric M
11,515 Points

Hi Theodore,

This code is actually pretty good, it looks like you might have been on a bit of a roll and enthusiastically put an extra N in WINNER in your return statement. That's the only straight up error I see.

When it comes to coding convention however some programmers will find reading your code confusing due to your use of all caps variables. All caps variables are by convention used for constant values that don't change (during the running of the program) but still need to be hard coded in.

For example:

#Global Constants
TAX_RATE = 0.1

Best of luck, looks like you're doing great!

Dude thanks for the extra info. Im pretty new to all this and learning new things like the global constants ^. I usually play around in sublime text editor, but i was goofing around a little too much for this not thinking about; what if i got something wrong? lol. thanks so much, again.

Schaffer Robichaux
Schaffer Robichaux
21,728 Points

Sooo close-

  • Looks like you added an extra "N" in you last statement return WINNNER
  • I tested it and it provides the expected results thereafter


OEEE man, Thank you for helping me! I thought I was losing it. ive taken a break since then, but i feel good about getting back to it, thank you again.

Eric M
Eric M
11,515 Points

No sweat!

Little errors like this can cause huge headaches later on, and they're pretty common because they're so easy to make. If you write a large and complex program try using an IDE that can automatically check for this stuff like PyCharm or VS Code with a Python linter.

Vivienne Owusu-Ansah
Vivienne Owusu-Ansah
3,142 Points

def most_courses(The_D): MAX_COUNT=0 name="" for teacher, courses in The_D.items(): if len(courses)>(MAX_COUNT): MAX_COUNT=len(courses)

return WINNNER

last two lines the function must return name.

return name