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 want some help

I don't understand what i'm supposed to do in this challenge. Can someone explain this challenge for me and give me a hint

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):
    new_list =[]
    for topic in topics:
        new_list.append(topic)
    return new_list

1 Answer

Philip Schultz
Philip Schultz
11,437 Points

Hey Mark, For task 1, it wants you to cross reference a list of topics with the values in the COURSES dict. If there are common topics then it wants you to add the key value of the COURSES dict to a list. So, that means it wants you to find the intersection of the set given and each value in the dict. So, I choose to loop through dict using the .items method, so I have access to both the key and the value at all times within the for loop (there are other ways, but this makes it clear to me). Note how I'm checking each value of the dict with the argument(topics) using the '&' symbol, this is the intersection. If there is something in common between the two sets then I add the key to a list.

def covers(topics):
    common_topics = []
    for key, value in COURSES.items():
        if value & topics:
            common_topics.append(key)
    return common_topics
Philip Schultz
Philip Schultz
11,437 Points

Let me know if you have questions and I'll try to help the best I can.