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 trialRalph Hellstern
6,106 PointsQuestion 3 of 5
Hi, I am stuck with question 3 of 5. What is wrong with my code? Thanks in advance.
# 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(dict):
return len(dict)
def num_courses(dict):
counter = 0
for value in dict.values():
counter += len(value)
return counter
def courses(dict):
list = []
for value in dict.values():
list = dict.extend(value)
return list
1 Answer
Josh Keenan
20,315 PointsHere's my solution, it uses a for loop to iterate over the values (courses) each teacher has, then for each list of courses it starts a new for loop, to go through the list of their courses and then appends them to the course_list
def courses(arg):
course_list = []
for value in arg.values():
for i in value:
course_list.append(i)
return course_list
Ralph Hellstern
6,106 PointsRalph Hellstern
6,106 PointsThank you!