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

Code works in Workspace but not in Challenge Task 1 of 5

The code works in workspaces but does not work in the Challenge window. I passed the dictionary two ways in the workspace:

  1. I named the dictionary teacher_dict = {...} and passed it to the function num_teachers(teacher_dict)

  2. I passed it as a param: num_teachers(kwargs={...})

Both worked counted the number of teachers in the dict. But in the challenge window I get a Type error, something about positional arguments.

I accept a dictionary and return an integer. What is wrong?

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(**kwargs):
    return len(kwargs.keys())

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Edward,

The instructions specify to write a function that takes a single argument, a dictionary... You are attempting to handle a case where there are an unknown amount of keyword arguments.

It doesn't matter how many keys or values are contained in this dictionary (that is what the function will figure out), but it should be passed in as a single argument, not as a double starred argument.

Hope this helps.