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

Code works as expected in my terminal, but challenge says I don't have the right output

Tried covers({"strings"}) and got ['Python Basics', 'Java Basics', 'PHP Basics', 'Ruby Basics'], as expected. Also tried covers({"loops"}) and covers({"Python"}) and got expected outputs.

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):
    li = []
    for x in COURSES:
        if topics & COURSES[x] == topics:
            li.append(x)
    return li

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are very close. The if condition is overly specific.

# This says "if the *all* the supplied topics are covered in the course *x*"
        if topics & COURSES[x] == topics:

# The challenge is only looking if *any* of the supplied topics are in each course *x*

I'll leave the change needed for you to figure out. Hint: it's a simpler condition than above!

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