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 trialfabian moreno
2,646 Pointsi dont just understand how i have to return the method type
i just dont know the type to return in the method definition, because it says list of list but the argument says in the example, that the method has to return the name of the teacher and the number of classes.
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.
def most_classes(dict):
max_classes = 0
name = ""
for var in dict.values():
if len(var) > max_classes:
max_classes = len(var)
name = "Jason Seifer"
return name
def num_teachers(dict):
count = 0
for key in dict:
count += 1
return count
def stats(dict):
new_list = []
text = "{name}, {number}"
for key in dict:
count = 0
for var in key:
count += 1
new_list.append(key + ", " + str(count));
return new_list
2 Answers
John Hill
Front End Web Development Techdegree Graduate 35,236 PointsHey, here's an answer from another thread (https://teamtreehouse.com/forum/function-is-supposed-to-take-a-list-but-when-i-put-an-arg-in-the-function-it-asks-where-stats-is):
def stats(arg3):
teacherList = []
for key in arg3:
tempList = []
tempList.append(key)
tempList.append(len(arg3[key]))
teacherList.append(tempList)
return teacherList
It looks like two lists are created in the function.
Mar Bocatcat
7,405 PointsHey Fabian,
The type to return would be a list of list. It looks like you are almost there. Try creating a list , and putting that list into another list . Hint is below.
fabian moreno
2,646 Pointsfabian moreno
2,646 Pointsthanks!! it solved my doubt....