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

I'm getting a Type Error on Challenge Task 1 of 5

This is the error that I am getting: TypeError: num_teachers() takes 0 positional arguments but 1 was given

# 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(**numberofTeachers):
    for teachers in numberofTeachers.key():
        return numberofTeachers.count(key)

2 Answers

Easy one liners to solve it will be these reply if you need more explanation

num_teachers = lambda arg: len(arg.keys())
num_courses = lambda arg: sum([len(c) for c in arg.values()])
courses = lambda arg: [c for s in arg.values() for c in s]
most_courses = lambda arg: [t for t, c in sorted(arg.items(), key=lambda a: len(a[1]), reverse=True)][0]
stats = lambda arg: [[t, len(c)] for t, c in arg.items()]
15,472 Points

Your function is expecting keyword arguments such as:

num_teachers(name='Ken', classes=['Python', 'Collections'])

not positional arguments such as:


I can't tell from your code, but my guess is you are trying to pass in a dictionary which is a positional argument since it is not unpacked by Python. Here's how I would handle the assignment:

def num_courses(teachers):
for key in teachers:
courses = len(teachers[key])
print("{} teaches {} courses.".format(key, courses))

then call the function using the teachers dictionary:

data = {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'], 'Kenneth Love': ['Python Basics', 'Python Collections']}

the output would look like the following:

Kenneth Love teaches 2 courses.
Andrew Chalkley teaches 2 courses.

This is assuming you are counting classes for each teacher. From this you should be able to revise your code for counting the number of teachers.