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

Anthony Lopez
Anthony Lopez
963 Points

Set Math task 1

Can someone help me to understand why my code isn't working?

If it is a subset of the sets with in the dict it should append that key into the list, and return the list at the end.

Doesn't seem to be taking this answer though.

    "Python Basics": {"Python", "functions", "variables",
                      "booleans", "integers", "floats",
                      "arrays", "strings", "exceptions",
                      "conditions", "input", "loops"},
    "Java Basics": {"Java", "strings", "variables",
                    "input", "exceptions", "integers",
                    "booleans", "loops"},
    "PHP Basics": {"PHP", "variables", "conditions",
                   "integers", "floats", "strings",
                   "booleans", "HTML"},
    "Ruby Basics": {"Ruby", "strings", "floats",
                    "integers", "conditions",
                    "functions", "input"}

def covers(param):
    new_list = []
    for item in COURSES:
        if param.issubset(COURSES[item]):
    return new_list

1 Answer

The param doesn't necessarily have to be a subset of COURSES[item]. Notice that the challenge says:

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

Therefore just has to have an intersection. Try this instead:

if param.intersection(COURSES[item]) != set():

Other than that, your code is great!

Anthony Lopez
Anthony Lopez
963 Points

Thanks Alexander.

So just so I understand, my code should be working?

If you copy-and-paste your code into the code challenge, it doesn't work. It isn't supposed to work.

If you pass in a set that is not completely a subset of a topic, but still has a couple items in common, it should still be part of the returned result.

Anthony Lopez
Anthony Lopez
963 Points

That answer is purely mine. No copy paste. That's why I'm a bit confused. When I used the ide it returned an empty list as well. Something in that code isn't working I'm just not sure why.

Also what is the purpose of comparing the intersection of the sets with set()?

Your code worked thanks.

The != set() bit checks if the intersection is an empty set. Basically, its checking whether or not there is an intersection or not.