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

Yaron Wainberg
Yaron Wainberg
4,426 Points

create a function named stats...

Hi

i set the function to :

def stats(teacher): for key in teacher: return key, len(teacher[key])

in my computer i run it as single command and got the desired results of a list of teachers and number of classess

why isn't it working on the workspace ?

1 Answer

Not sure how it worked on your computer I couldn't get it to work in my terminal.

the code below works in both though (just put your code on multiple lines with proper indentation)

def stats(teacher):
    for key in teacher:return key, len(teacher[key])

#This works too
def stats(teacher):
    for key in teacher:
        return key, len(teacher[key])