Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Sets Set Math

return a list of courses from COURSES where the supplied set and the course's value (also a set) overlap.

I've tested this several different ways and it seems to work, but it fails the challenge. Not looking for a solution, just a clue as to what I am missing.

def covers(topics): # topics = type set

    list_of_courses = [] # the key for topics that overlap
    # compare topics w/ dct value
    # if topics and value overlap
    # append key to list_of_courses
    for key, value in COURSES.items():
        if value.intersection(set_of_topics):
            list_of_courses.append(key)
    return list_of_courses

Thanks you Jason, I appreciate your help.

1 Answer

Hi John,

It's hard to give a hint on this without giving away the solution because you're so close.

Take a look at the names of your variables. topics is the parameter to your function. Where are you using that in your code?

Thanks Jason. I fixed that, now I have:

def covers(topics): # topics = type set
    list_of_courses = [] # the key for topics that overlap
    # compare topics w/ dct value
    # if topics and value overlap
    # append key to list_of_courses
    for key, value in COURSES.items():
        if value.intersection(topics):
            list_of_courses.append(key)

But it's still not passing. Any other clues?

You're missing the return statement that you had originally.

This new code passes once I add that in.