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

wayne ross
wayne ross
3,225 Points

When I test out the code on various data sets (dictionaries similar to the example) it works but not for the task answer

The function should accept a dictionary arg in the format of {'teacher1':['courses']...etc and return a list of lists that have the first value as the name and second as the amount of courses Please See the 'stats' function

def stats(arg5): retValue=[] for key,value in arg5.items(): retValue.append([key,len(value)])

return(retValue)
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(arg1):
    return1=0
    dictA=arg1
    for key in dictA:
        return1 +=1
        continue
    return(return1)

def num_courses(arg2):
    return2=0
    dictA=arg2
    for key in dictA:
        return2 += len(dictA[key])
        continue
    return(return2)

def courses(arg3):
    return3=[]
    dictA=arg3
    for key in dictA:
        return3.extend(dictA[key])
    return(return3)

def most_courses(arg4):
    return4=[]
    courseLen=0
    dictA=arg4
    for key in dictA:
        if len(dictA[key])>courseLen:
            return4=key
            courseLen=len(dictA[key])
        else:
            continue
    return(return4)

 def stats(arg5):
        retValue=[]
        for key,value in arg5.items():
            retValue.append([key,len(value)])

    return(retValue)

1 Answer

I think it might be because you have a space before the ' def stats(arg5):' and the 3 lines you have under that are indented too far.

Let me know if that helps.

Also, I don't think you need to put the stuff you want to return in brackets...

wayne ross
wayne ross
3,225 Points

Mark you where correct indentation got me!!!! thats prob why its not good to do this stuff tired. Thanks