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

I've been struggling with all of the challenges since the challenges in the Dictionary section... don't get this

I don't understand what is asking me to do. I'm not sure if it is the wording of the questions, or if it is just me

sets.py
def covers(topic):


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"}
}

1 Answer

Ivan Kazakov
PLUS
Ivan Kazakov
Courses Plus Student 43,317 Points

I approached that as an evaluation of intersections (&) of target topicSet with topic sets of each course. If there are, I added the course to what is returned:

def covers(topicSet):
    result = []

    for course, topics in COURSES.items():
        if len(topics & topicSet) > 0:
            result.append(course)

    return result

Thanks, it's just I didn't understand what they were actually asking me to do. I find that some of the challenges are written in a way I don't understand. Your code makes complete sense to me however, so thanks for that. I'll just try and see how it relates to the question to gain a better understanding