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) 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.