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

Taebin You
Taebin You
4,786 Points

Too many values to unpack on Teacher Stat

It says too many values to unpack. What is wrong with my code?

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):
  most_class = ""     # holds the name of teach with most class
  max_count = 0       # max counter for classes
  for teacher in dicts:
    if len(dicts[teacher]) > max_count:
      max_count = len(dicts[teacher])
      most_class = teacher
  return most_class

def num_teachers(dicts):
    teacher_count = 0
    for teacher in dicts:
        teacher_count += 1
    return teacher_count

def stats(dicts):
    newList = []
    for teacher, dicts[teacher] in dicts:
        newString = [teacher, int(len(dicts[teacher]))]
        newList.append(newString)
    return newList

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Taebin,

You are very close. Try making the for statement the same as your other functions. Also, you don't need to convert the len(dicts[teacher]) to an int, since the len() function already returns an int, although it should still work either way.

def stats(dicts):
    newList = []
    for teacher in dicts:
        newString = [teacher, len(dicts[teacher])]
        newList.append(newString)
    return newList
Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Ryan.

Please note I have changed your comment into an answer.

Thanks! ;)

Ryan S
Ryan S
27,276 Points

Thanks Vittorio

Taebin You
Taebin You
4,786 Points

Thx I couldn't choose it as Best answer because it was a comment!