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 (Retired) Dictionaries Teacher Stats

Hunter G
Hunter G
6,612 Points

Do not understand the Teacher Stats challenge AT ALL!

Hello everybody. So I was able to finish this whole problem resourcing other forum posts, but I am still not understanding exactly what the functions are doing and what their outputs would be. Typically when I don't understand something, I make a new file and enter the code in the Workspaces to help me understand. BUT, when I run the code (without the print command which is the very last line of the code), the console prints back nothing.. And when I enter in the print (most_classes) command, the console returns the following : function most_classes at 0x7fc5b3ccaf28 (with a less than symbol at the beginning and a greater than symbol at the end).

Can somebody clarify this for me and explain what I need to fix so I can see exactly what the functions are going to print out?

teachers.py
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.

my_dict = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'], 'Kenneth Love': ['Python Basics', 'Python Collections'] }

def most_classes(my_dict):
    count = 0
    teacher = ""
    for key in my_dict: 
        if(len(my_dict[key]) > count):
            count = len(my_dict[key])
            teacher = key   

    return teacher

print (most_classes)

1 Answer

Seth Reece
Seth Reece
32,867 Points

Hi Hunter,

In this script you have a function named most_classes. It takes one argument, a dictionary. When you call a function with an argument, you need to pass an argument into your call. e.g.

print most_classes(my_dict) # my_dict could be any dictionary that you have defined.

When using:

print (most_classes)

The console output is telling you that most_classes is a function, and it is currently stored in memory location 0x7fc5b3ccaf28.

Hunter G
Hunter G
6,612 Points

Hey Seth, thanks for your reply!

Doh! Including the argument totally slipped my mind! Whoops!