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!

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

Adam Tyler
Adam Tyler
14,865 Points


This works inside workspaces, I have checked by giving covers several different arguments. But I can not pass the code challenge. Is something for a very specific case wrong which I just haven't picked up on in manually testing it?

    "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(top):

    #see if union is same as key, if so, add to list

    courses = []

    for i in COURSES.keys():
        if top.union(COURSES[i]) == COURSES[i]:

    return courses

3 Answers

Steven Parker
Steven Parker
225,712 Points

An "overlap" would e a case where two sets had one or more elements in common, But an equality between one set and the union of of it and another only indicates that the first doesn't contain anything that is not in the second. It doesn't indicate that they have any elements in common.

An intersection might be a better way to test for "overlap".

Adam Tyler
Adam Tyler
14,865 Points

But it works in workspace, the idea was that if the union of the two sets is the same as the second set, then the first set is a subset of the second and therefore, as its a subset, they have elements in common and therefore it should work?

Steven Parker
Steven Parker
225,712 Points

It wouldn't have to be a subset, it could just be empty. The union would still match the other set, but they would have no elements in common.

Alex Koumparos
Alex Koumparos
Python Development Techdegree Student 36,886 Points

When you say it works in workspace, did you check the empty set?

In set theory, the union of the empty set and set A is set A; the intersection of the empty set and set A is the empty set. Accordingly, this would be a a specific case where your code, which uses union, would produce a different answer from what the challenge wants, which is intersection.