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

Daniele Santos
Daniele Santos
16,536 Points

It runs on my PyCharm but it won't pass the tests on Workspaces. Why?

I don't understand why this is not working. Anyone has 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):
    topic_list = []
    for key in COURSES:
        if topic.intersection(COURSES[key]):
            topic_list.append(key)
            return topic_list

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

You are very close to the correct answer. I pasted in your code and changed the indentation a tiny bit. The way you had it, it would work on some tests, but fail on some of the deeper tests run by the code challenge.

Good luck with Python!

def covers(topic):
    topic_list = []
    for key in COURSES:
        if topic.intersection(COURSES[key]):
            topic_list.append(key)
    return topic_list  # fix your indentation here to this.
Daniele Santos
Daniele Santos
16,536 Points

Thanks for taking the time to check my code, Jeff!