Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!

teachers.py
# 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:
            new_list.append(item)
    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])
    print(new_list)

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