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 trialMichel Branquet
1,388 PointsPython collections: Task 3 out of 5 Why is my code not populating a list?
In the third snippet of code, I am creating a function with one variable in the argument. Then, I am creating an empty list. After, I am writing a for loop to get all the values inside the dictionary. Also, I am appending/extending (neither worked) to the "t_course" empty list via "cour" and trying to return all the courses in a single list unsuccessfully!
# 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):
t_courses = 0
for courses in _dict.values():
t_courses += len(courses)
return t_courses
def courses(_dict):
t_courses = []
for cour in _dict.values():
t_courses.extend(cour)
return t_courses
1 Answer
KRIS NIKOLAISEN
54,972 PointsI pasted your code into the challenge and it passed
Michel Branquet
1,388 PointsMichel Branquet
1,388 PointsIt is the first time I encounter that possibly lag makes it mark it incorrect. Thank you for checking it out.