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 trialwayne ross
3,225 PointsWhen 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)
# 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
Mark Fawcett
13,109 PointsI 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
3,225 Pointswayne ross
3,225 PointsMark you where correct indentation got me!!!! thats prob why its not good to do this stuff tired. Thanks