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

covers function not working

My code doesn't work in the editor but it works on my personal IDE. I tried changing the spaces to tabs. But it keeps telling me that it's not getting the right result for covers.

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(topic):
    lst = []
    for course, topics in COURSES.items():
        if topic.issubset(topics):
            lst.append(course)
    return lst

1 Answer

Steven Parker
Steven Parker
231,275 Points

It's not your indentation. But the function should produce a list of classes where the topics overlap. By "overlap" they mean if it has any topics in common. But a subset only exists when the set has every topic in common with the other set. So this is not the right test for this function (it might be useful later, though!).

See if you can find a different method that will meet the specific needs of this function.

Thanks, I used "if not isdisjoint(topics)" that worked for me

Steven Parker
Steven Parker
231,275 Points

I assume you meant "if not topic.isdisjoint(topics):" — and very clever! :+1: I don't think I've seen that method used for this before.