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 trialAbdullah Jassim
4,551 PointsI am not sure why the answer is wrong
def courses(arg):
single_list = []
for course in arg.values():
single_list.append(course)
def num_teachers(arg):
teachers = int(len(arg))
return teachers
def num_courses(arg):
count_courses = 0
for values in arg.values():
for number in values:
count_courses += 1
return count_courses
def courses(arg):
single_list = []
for course in arg.values():
single_list.append(course)
# 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.
2 Answers
Unsubscribed User
7,263 PointsHello Abdullah, you have the right idea but when you iterate through the values the item you get is a list with courses. You have to iterate in this list again and then append courses in your list.
something like this:
single_list = []
for list_of_courses in args.values():
for course in list_of_courses:
single_list.append(course)
or if you don't want to make another for-loop you can use list comprehensions like this:
single_list = []
for list_of_courses in args.values():
single_list.extend([course for course in list_of_courses])
Philip Schultz
11,437 PointsHello Abdullah, Remember that you need to use a for loop to access each value, but since you values are lists you have to loop through that also.
def courses(sing_arg):
list_courses = []
for values in sing_arg.values():
for courses in values:
list_courses.append(courses)
return list_courses