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 trialjohn larson
16,594 PointsThis passed the challenge, but there's an extra empty list I'd like to get rid of
def stats(teachers_dict):
final_list = []
name_num1 = []
name_num2 = []
for teacher in teachers_dict:
if teacher in teachers_dict == "Jason Seifer":
name_num1.append(teacher)
name_num1.append(len(teachers_dict[teacher]))
else:
name_num2.append(teacher)
name_num2.append(len(teachers_dict[teacher]))
final_list.append(name_num1)
final_list.append(name_num2)
# print(teachers_dict[teacher])
print(final_list)
return final_list
stats(teachers_dict)
there's an extra empty list at the beginning of the line
[[], ['Jason Seifer', 3, 'Kenneth Love', 2]]
1 Answer
jacinator
11,936 PointsThis code is rather shorter and does the trick.
def stats(teachers):
teachers_list = []
for teacher, classes in teachers.items():
teachers_list.append([teacher, len(classes)])
return teachers_list
john larson
16,594 Pointsjohn larson
16,594 PointsNow that I'm looking at it I don't think I needed the extra step of appending name_num1 and name_num2 into final_list.