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

create a function called stats

So, challenge question for collections. Here is my code. I can't tell if it's correct because I get the "Oops! It looks like Task 1 is no longer passing" which I assume is because of an indentation problem or the like. (I seem to get that at least once a challenge). It's not very a descriptive error.

Help!

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(teach_dict):
  most = 0
  teacher = ''
  for teach in teach_dict:
    if len(teach_dict.values()) > most:
      most = len(teach_dict.values())
      teacher = teach
  return teacher

def num_teachers(teach_dict):
  teachers = 0
  for teach in teach_dict:
    teachers += 1
  return teachers

def stats(teach_dict):

  teach_list = []
  for teach in teach_dict:
    grints = [teach, len(teach_dict[teach])]
    teach_list.append(grints)
  return teach_list

3 Answers

AttributeError: 'list' object has no attribute 'values' download python program to check the errors yourself https://www.python.org/downloads/

Tony Gibbons
Tony Gibbons
1,573 Points

I just had a similar issue where I needed to put a space between the for loop and the return

def num_teachers(teach_dict):
  teachers = 0
  for teach in teach_dict:
    teachers += 1

  return teachers

def stats(teach_dict):

  teach_list = []
  for teach in teach_dict:
    grints = [teach, len(teach_dict[teach])]
    teach_list.append(grints)

  return teach_list

See if that helps

Thanks, guys. I will give that a shot. It's a very strange thing. If I keep pressing the 'check work' button, it eventually accepts the code and give me the 'congrats' or 'bummer' message (depending on if I get me code right). Perhaps a bug in the system?

Tony Gibbons
Tony Gibbons
1,573 Points

Ah yes I see what you mean, if you press it 7/8 times it changes from "Task 1 is no longer passing" to what ever the problem actually is. I think the real bug is that it tells us that Task 1 doesn't work anymore since that never seems to be the problem! Has taking the returns out of the loop helped?