Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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