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

Return a list of lists?

how do i go about this one good people i am a bit rusty

teachers.py
teacher_dict = {'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.
def most_classes(teacher_dict):
  return "Jason Seifer"
def num_teachers(teacher_dict):
  max_count = 0
  max_count = len(teacher_dict)
  return max_count
def stats(teacher_dict):

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Wolverine.

I presume you are stuck at challenge 3/4; but before having a look at it, I noticed one thing in your code for the previous challenges and in particular the most_classes function definition: it should be the compiler's job to find which teacher has the most courses and not you like in your code. So it has to return a string but not one that is hard-coded by you.

Regarding task 3/4 I can try to point you in the right direction: there is a handy method in python which is the items() method: it unpacks all the values of the dictionary (2 in our case) and I think it is a good starting point for you in this situation (I have used it myself too).

Something like this:

for teacher, course in dictionary.items():

This would then give you the chance to have both teacher and courses from the dictionary.

Let me know if clear

;)

Vittorio

Hi Wolverine,

I agree with Vittorio regarding task 1. You really should go back and try to solve it so you can learn from it. Figuring out the expected answer and returning that directly doesn't help you much.

In case you're not sure about the structure of the output I'll give one further hint.

Using the example dictionary the output would be something like:

[['Jason Seifer', 3], ['Kenneth Love', 2]]

This is what is meant by a 'list of lists'.