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!

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 (2016, retired 2019) Dictionaries Teacher Stats

Todd Costa
Todd Costa
3,380 Points

Task 5/5 - 'NoneType' is not iterable but works correctly in workspaces

Hey guys, title really says it all. I'd like to understand why it doesn't work. Thanks in advance!

# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}
# Each key will be a Teacher and the value will be a list of courses.
# Your code goes below here.
def num_teachers(teachers):
    return len(teachers.keys())

def num_courses(courses):
    count = 0
    for course in courses.values():
        for item in course:
            count += 1
    return count

def courses(courses):
    new_list = []
    for course in courses.values():
        for item in course:
    return new_list

def most_courses(arg):
    max_count = 0
    teachers = " "
    for teacher, listOfCourses in arg.items():
        if len(listOfCourses) > (max_count):
            max_count = len(listOfCourses)
            teachers = teacher
    return teachers

def stats(a_dict):
    new_list = []
    for teacher in a_dict.keys():
        num_courses = len(a_dict[teacher])
        new_list.append([teacher, num_courses])

3 Answers

Brendan Chamberlain
Brendan Chamberlain
2,753 Points

Your code is fine you're just printing your new_list variable instead of returning it.

Todd Costa
Todd Costa
3,380 Points

Thank you! I'm happy its a silly mistake at least.

Jose Lopez
Jose Lopez
4,615 Points

I am very confused. Why are you using the len() function? I keep getting an error when I use it