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

someone please help me out with this it does not make any sense

someone please help me out with this it does not make any sense and please go into detail and explain

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(teachers):
    count = 0
    for teacher in teachers:
        count += 1
     return count

your return statement is indented wrong. hope you figured it out.

1 Answer

Eduardo Valencia
Eduardo Valencia
12,444 Points

Hi. That part of the question asks that you find out the total number of teachers. To figure this out, you need to first find out what information you will receive. The problem states that you will get a dictionary of teachers, with each teacher's name being a key. Each value will be a list of the courses that the teachers teaches. The dictionary will look like this:

{
    "Adam": [
        "course1", "course2", "course3
    ],
    "John": [
        "course1", "course2", "course3"
    ]
}

When you use the Len() function on a dictionary, it will give you how many items there are in it. You get a dictionary with teachers, and you want to find out how many there are. Therefore, you can use the len() function on it to find out how many teachers there are.

Therefore, the function that you have to write is simple:

def num_teachers(teachers):
    return len(teachers)

Although you could have used a for loop, I find that returning the length of the dictionary of teachers is much easier. I hope this helped!