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

Michael Spinks
Michael Spinks
1,150 Points

missing 1 positional argument.

I have defined my function as taking the arguments (teachers, dicts). When I run the code I am told I am missing 1 positional argument "dicts". If I switch the order I am told I am missing 1 positional argument "teachers". I need to pass both dictionaries to the functions. if I run this function in the python interpreter on my PC it returns the expected results.

teachers.py
# The dictionary will be something like:
# {'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(dicts):
  my_dict = {}

  for i, j in dicts.items():
#       print i
        my_dict[i] = i
#       print my_dict[i]
        count = 0
      # add i as the value in our own dictionary
        for k in j:
      #     print k
            count += 1
      # print count 
        my_dict[i] = count

  return max(my_dict, key=my_dict.get)

def num_teachers(teachers):


    max_count = 0
    max_count = len (teachers)

    return max_count

def stats(dicts):   

    list_of_lists = []
    stat_list = []

    for i, j in dicts.items():
        count = 0
        for k in j:
            count += 1
        stat_list = [i,count]
        list_of_lists.append (stat_list)

    return list_of_lists    

def courses(dicts, teachers):

    course_list = []

    for i, j in teachers.items():
    #   print dicts[j]
        course_list.extend(dicts[j])

#   print course_list

    return course_list

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Michael.

We only need to pass in 1 argument into the function as in the previous challenges.

All the data is in that single dictionary (like the example you may read at top of the code challenge, the lines that are commented out).

All the output that we want to return comes from that single dictionary.

Your code is pretty close to the solution, you only need to loop like you did and just append the right value to the list you have initialized with your code and you should be good to go.

Vittorio