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 trialConner Williams
Courses Plus Student 3,305 PointsWhat is the proper way to solve the 5th task?
I have tried quite a few different approaches to the list.append/update line in this code. I am convinced that is where the error lies but, i cannot seem to make it work. Help is much appreciated!
# 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(teachers):
count = len(teachers.keys())
return count
def num_courses(teachers):
number = []
for value in teachers.values():
number += value
return len(number)
def courses(teachers):
courses = []
for course in teachers.values():
courses += course
return courses
def most_courses(teachers):
max_count = 0
teach = " "
for teacher,courses in teachers.items():
if len(courses) > (max_count):
teacher = teacher
max_count = len(courses)
return teacher
def stats(teachers):
list = []
for teacher,courses in teachers.items():
list.append([teachers.keys(), len(teachers.values())])
return (list)
1 Answer
Nader Alharbi
2,253 PointsHello there. When you call teachers.items() you don't need to type .keys() or .values() because you already gave them names (teacher & courses).
def stats(teachers):
list = []
for teacher,courses in teachers.items():
list.append([teacher, len(courses)])
return (list)