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

Teachers stats, task 3

EDIT: It turned out to be a mistake on team treehouses side. They didn't accept the argument I had put in, even thought he code would have worked anyways. I get the message "Didn't get the expected output. Got [['Jason Seifer', 3], ['Kenneth Love', 2]]." but isn't that exactly the output it would expect? What am I missing?

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.

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

def stats(argument):
    stats_list = []
    for key, value in teachers.items():
        stats_list.append([key, len(value)])
    return stats_list

print(stats(teachers))

2 Answers

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

That's the kind of format that function should return however grader might pass additional dictionaries during the check. The problem with this is that your code only knows how to handle two specific people so any less or more or even same dict with different teacher name might break your code.

I am not sure I understand what you are saying?

Anyways I fixed it now, I just had to change the argument from "argument" to "teachers". So seems to be just a problem with team treehouse, since my code worked fine in cmd.

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

I was saying the grader program that checks your code might send different dictionary as argument and your code cannot handle that.

For example, if given argument was

{'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
  'Kenneth Love': ['Python Basics', 'Python Collections'], 
  'Cool Guy':['C', 'C++', 'C#', 'GO']}

Your code will break because it doesn't expect Cool Guy to be in the dictionary. I'm just saying there is a way that will let you handle any number of teachers and courses. But based on what you said, grader only passes what it asked for so if you are satisfied with that it's all cool.

How come that is? Why wouldn't it?

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

Oh did you revise your code? Your revised one works. I posted my answer when you had 2 for loops to loop each of teacher's course, bear in mind.

Oh right, the ugly j_count, k_count code? Yeah I showed it to my brother and got scolded for how ugly a code that was, and he helped me simplify it. But it still gave me an error, turned out to be the argument.

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

Alright I see happy coding.