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 (2016, retired 2019) Dictionaries Teacher Stats

teacher stats

im really lost in this challenge and would appreciate if anyone can explain it

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(my_dict): teachers_list = {'andrew': ['jquery', 'node'], 'kennneth': ['python']} for teacher in my_dict: teachers_list[teacher] = len(my_dict[teacher]) return max(teachers_list)

teachers.py
# 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(my_dict):
    teachers_list = {'andrew': ['jquery', 'node'], 'kennneth': ['python']}
    for teacher in my_dict:
        teachers_list[teacher] = len(my_dict[teacher])
        return teacher.len(teachers_list)
Raduica Sebastian
Raduica Sebastian
Courses Plus Student 1,356 Points

Hi there! First , the dictionary that you must use in your code is not exactly the one that is shown in the example.It can be one with more keys. So you don't need : teachers_list = {'andrew': ['jquery', 'node'], 'kennneth': ['python']}

in order to loop through the teachers inside the dictionary , you have to use .keys() method like this: for teachers in my_dict.keys() This allows you to loop only through the teachers. Create a empty variable : number_of_teachers[] , like this, and append every teacher with append() method, so you'll have: for teachers in my_dict.keys(): number_of_teachers.append(teachers) Then in a new variable that you create you will place the length of number_of_teachers like this: new_variable=len(number_of_teachers) And at the end you will return new_variable. Hope this helps. Let me know if you hace questions.

1 Answer

Ashley Keeling
Ashley Keeling
11,476 Points

Hi I have just completed this challenge ,the first one is:

def num_teachers(dict):

len_dict=len(dict)


return len_dict

you don't need a teacher list ,it I already there.

sorry the code isn't displaying right, if you type it is will work