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

Challange task 4 of 4 appears bugged, "'Nonetype' has no len()" error

First 3 tasks are running perfectly. However, when I start 4th task it doesn't let code from the first 3 through saying “object of type 'NoneType' has no len()” in the error message. Even if I put 4th function as blank. Oh, and even when I remove all the len() calls with manual for loops for counting.

I tried reloading browser, clearing cookies, re-doing the task, nothing is working :(

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(myDict):
  winrarTeacher = ""
  winrarClasses = 0
  for teacher in myDict.keys():
    numClasses = len(myDict[teacher])
    if numClasses > winrarClasses:
      winrarTeacher = teacher
      winrarClasses = numClasses
    else:
      continue
  return winrarTeacher

def num_teachers(myDict):
  return len(myDict)

def stats(myDict):
  myList = []
  try:
    for item in myDict:
      #myList.append([item, myDict[item]])
      count = 0
      for subItem in myDict[item]:
        count += 1
      myList.append([item,count])
  except:
    fYou = True
  return myList

def courses(myDict):
  allCourses = []
  for item in myDict:
    allCourses.append(myDict[item])

It fixed itself. Error was made because code calls len() on what's returned from 4th function. My code on 4th: def courses(myDict): allCourses = [] for item in myDict: allCourses.extend(myDict[item]) return allCourses

omigod, I got so stressed out and spent 30 minutes in like stress :c / c:

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Your courses function doesn't return anything. So when the validator calls it, the validator just gets back None, which doesn't have a length.