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

Gali B
Gali B
2,082 Points

The code works on IDE but not on Treehouse RIPL

Hey, I'm using JetBrains PyCharm as my IDE. I wrote the following code:

def covers(param):
    lst = []
    set1 = {param}

    for key, value in COURSES.items():
        if set1.intersection(value):
            lst.append(key)


    return lst

When calling the function by: print(covers("Python"))

I get the following output: ['Python Basics']

Which by the example given by Treehouse for this exercise, I've done it as required. If so, why when checking the code I being told to "try again?"

*And yes, I've tried to refresh my browser and paste the code again.

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(parm):
    lst = []
    set1 = {parm}
    for key, value in COURSES.items():
        if set1.intersection(value):
            lst.append(key)


    return lst
Gali B
Gali B
2,082 Points

Don't really know why, but the '''set1 = {parm}''' was the problem.. now I wrote:

def covers(param): lst = []

for key, value in COURSES.items():
    if param.intersection(value):
        lst.append(key)

return lst

and it works.

1 Answer

Remove set1 and replace the if statement's condition with:

param.intersection(value)