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

Everett Yates
Everett Yates
9,280 Points

Need help with Task 2

I've been rackin' my brain on Task 2 for a while, can't figure it out. Please help

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):
    l = []
    for key, value in COURSES.items():
        if value & topic:
            l.append(key)

def covers_all(myset):
    hold = []
    for course, value in COURSES.items():
        if (myset & value) == myset:
            hold.append(course)

1 Answer

jonlunsford
jonlunsford
15,480 Points

Everett:

Looks like you are really close. In your covers function, this one should work so you just need to return your new list from the function.

return l

For the second function, covers_all, in the for loop I would use the .issubset() function to test if myset was completely contained within the value dictionary, such as.

if myset.issubset(value):
hold.append(course)

Just to make this more clear -- you would remove the if(myset & value) == myset statement. This should get you on your way to passing this step.