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

Now it's just getting bizarre...challenge is telling me it got output that I DID NOT PUT!!!

Bummer! Didn't get the expected output. Got ['Dave McFarland', 1, 'Kenneth Love', 2, 'Pasan Premaratne', 4, 'Jason Seifer', 7, 'Andrew Chalkley', 4].

  • you can see in my code I only have jason and kenneth, not the others
teachers_dict = {
'Jason Seifer': [
'Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
 'Kenneth Love': [
 'Python Basics', 'Python Collections']
 }

def stats(teachers_dict):

    name_num = []
    for teacher in teachers_dict:
        name_num.append(teacher)
        name_num.append(len(teachers_dict[teacher]))

    print(name_num)
    return name_num

stats(teachers_dict)

In that case, this code seems to work perfectly in my editor. Do you see anything wrong with this code?

def stats(teachers_dict):

    name_num = []
    for teacher in teachers_dict:
        name_num.append(teacher)
        name_num.append(len(teachers_dict[teacher]))

    print(name_num)
    return name_num
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Assuming we're looking at the challenge linked at the top here, my best suggestion is to carefully read the instructions for the challenge again. It explicitly says that the function itself is to be named most_classes. Also, the function (according to the instructions) is supposed to return the teacher that has the most classes. Currently, you're returning an array containing all teachers and how many classes they teach.

Hope this helps! :sparkles:

1 Answer

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

Hi there! Here's the thing. Treehouse is going to call the function and send in their own data for the teacher_dict. It could be absolutely anything. Your code needs to work for whatever Treehouse sends in. The teachers_dict in the comments is merely an example. So while your definition for teachers_dict only has those 2 teachers, this is obviously not true for the data set they're sending into your function.

Note: this is true for many challenges here on Treehouse.

Hope this helps! :sparkles:

Ok, I get it...thanks Jennifer.

I must have posted that code under the wrong question, sorry. This is what the challenge said to do:

  • return a list of lists containing all teachers and how many classes they teach.