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

victor E
victor E
19,146 Points

I think my issues is that the argument given is not unpacked, but idk

it is simply adding every item to the list. what am I missing?

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

def covers_all(topics):
    lst2 = []
    for key, value in COURSES.items():
        if topics & COURSES[key]
            lst2.append(key)
    return lst2

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Your code for covers and covers_all is the same. The first successfully checks "where the supplied set and the course's value (also a set) overlap." that is, if any of the topics are also in the course set. The second is supposed to verify that all of the topics are contained with the course topics. In this case, a simple "and" is insufficient.

Looking at the set operations available, which would check if every element in a set is contained in another set?

Post back if you need more help. Good luck!!

victor E
victor E
19,146 Points

well i tried using what you recommended but i still seem to be getting an error. the fact that I have not been on for a week does not help lol.

def covers_all(topics):
    lst2 = []
    for key, value in COURSES.items():
        if topics >= COURSES[value]:
            lst2.append(key)
    return lst2

[MOD: added ```python formatting -cf]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

You are very close. You should be using COURSES[key] not COURSES[value]. You are checking if the topics cover every topic in the course instead of the course covering topic in the topics set. Hint: reverse the >= to <=

Post back if you need more help. Good luck!