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 think this is close but I can't figure out what is wrong

Is there something about the output that formatted right?

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(a):
    b = list()
    for x in COURSES.items():
        for y in x:
            if y == set:
                if y & a == a:
                    b.append(x[0])
    return b

1 Answer

Juliana Arrighi
Juliana Arrighi
9,928 Points

Kenton, you're right. You're just a few edits away.

Right now, there's no way that the line b.append(x[0]) will ever get executed.

The main problem is in if y == set. It looks this line is meant to help find the set part of each item in the dictionary, but it won't quite work this way. To understand why, it might be helpful to try running something like {'a', 'b'} == set in an interactive Python shell to see what you get. I'd also recommend looking up the type function and the isinstance function.

In any case, there are a couple of different ways you can find the set part of each x that don't require you to iterate over the x's parts with for y in x. You could use x[1], similar to what you did in your second to last line or you could 'unpack' each dictionary item at the beginning of your first for loop. Something like for course, topics in COURSES.items():. Then you could compare topics or x[1] with a.

Once you fix that issue, take another look at if y & a == a:. The instructions say all you need is for the input to overlap with a course's topics. It doesn't need to match completely.