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 trialPrabhath Pillai
2,740 PointsAppending a list into a list. I'm having issues. Challenge task 3/4 "num_teachers"/"stats"
Hi,
I'm trying to append a list into a list but apparently "int" object is not subscriptable.
Please help me out!
Prabhath
# 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(teacher_dict):
big_num = 0
big_teacher = ''
for teacher in teacher_dict:
class_num = len(teacher_dict[teacher])
if (class_num > big_num):
big_num = class_num
big_teacher = teacher
return big_teacher
def num_teachers(teacher_dict):
teach = 0
for teacher in teacher_dict:
teach += 1
return teach
def stats(teacher_dict):
stat = []
for teacher in teacher_dict:
stat.append([teacher,len(teacher_dict)[teacher]])
return stat
1 Answer
Kenneth Love
Treehouse Guest Teacherlen(teacher_dict)[teacher]
is your problem. len(teacher_dict)
is going to give you the number of keys in teacher_dict
. You can't then look up the teacher
key in that integer.
Prabhath Pillai
2,740 PointsPrabhath Pillai
2,740 Pointscheers kenneth!