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

Hasan Ahmad
Hasan Ahmad
6,727 Points

Python math sets; Task 1 is no longer passing

I have hit another brick wall I guess... I have got this answer from another student but never really understood the concepts behind the code. One of the answers said that to use issuperset() method instead of intersection() method. I did as the answer said but now all it says is that task 1 is no longer passing!

sets.py
COURSES = {
    "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(single_parameter):
    empty_list = []
    for keys, values in COURSES.items():
        if single_parameter.union(values):
            empty_list.append(keys)
    return empty_list

def covers_all(single_parameter):
    new_empty_list = []
    for keys, values in COURSES.items():
        if single_parameter.issuperset(values):
            new_empty_list.append(keys)
    return new_empty_list

2 Answers

Christopher Shaw
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 Points

For Task 1 to pass, for the intersection of the two sets should be if single_parameter.intersection(values): not union that you have.

You will still need to work on your function covers_all

Hasan Ahmad
Hasan Ahmad
6,727 Points

Now it says that it didn't get the right output from covers_all

Michael Neimat
Michael Neimat
2,680 Points

try using difference instead of issuperset and look for an empty set as your result