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

I found a bug in this challenge!

Hi I was solving the second challenge of this when i found a bug about this. I used the comment you gave us which only showed 2 teachers. After I had touched up my code to account for Kenneth and Jason and tested it with vi, GVIM and Emacs I noticed it said that it said on treehouse after i had submitted it that it was expecting 5 and got two. Can you fix the dictionary in the example whenever you can? Thanks.

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.
B = 5
def most_classes(B):
  dic = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],'Kenneth Love': ['Python Basics', 'Python Collections']}
  k = 0
  b = 0
  for key in dic['Jason Seifer']: 
    k+=1 
  for key in dic['Kenneth Love']: 
    b+=1

  if b >= k:
    return 'Kenneth Love'
  else:
    return 'Jason Seifer'

most_classes(B)

C = 5
def num_teachers(C):
  dic = {'soup': ['oop'], 'moop': ['lop'], 'hoop': ['hi'], 'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],'Kenneth Love': ['Python Basics', 'Python Collections']}
  y = 0
  m = 5
  for value in dic:
    y+=1
  if  y == m:
    return m
  else:
    return y


num_teachers(C)

Could you give a longer dictionary instead of asking to add more yourself? I thought that would be easier for many other programmers.

1 Answer

There isn't a bug in this challenge... I think you might be going about this challenge the wrong way. It asks you to first:

Create a function named most_classes that takes a dictionary of teachers and returns the teacher with the most classes.

And then second:

Create a function named num_teachers that takes a dictionary of teachers and returns the number of teachers.

You're instead creating two functions that take an argument that isn't being used, and you're manually creating a bunch of local variables in each function for the data, instead of passing it as an argument to the function.

I'd suggest you go back to Python Basics again, particularly the stage on functions, and practice some more with that first.

Then, also rewatch the Dictionary Iteration video, since you need that for this challenge.