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 trial

Python Python Collections (2016, retired 2019) Dictionaries Teacher Stats

Abdullah Jassim
Abdullah Jassim
4,551 Points

I am not sure why the answer is wrong

def courses(arg):
    single_list = []
    for course in arg.values():
        single_list.append(course)
teachers.py
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

Hello 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
Philip Schultz
11,437 Points

Hello 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