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

Abdulkadir Kollere
Abdulkadir Kollere
1,723 Points

Sets issues

The code below gives me the desired result in workspaces as usual but does not allow me to pass the challenge. Kindly assist

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(elem):
    keys = COURSES.keys()
    for item in elem:
        for key in keys:
            values = COURSES[key]
            if item in values:
                print (key)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You have the correct idea. The function needs to return a list of the results. One way is to initialize an empty list at the top of the function, then append() each found course name instead of printing the matches. Finally, return the result.

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

Abdulkadir Kollere
Abdulkadir Kollere
1,723 Points

I did the changes as suggested, but it still says did not get the right output from 'covers'. See the code below:

def covers(elem):
    keys = COURSES.keys()
    total = []
    for key in keys:
        values = COURSES[key]
        if elem & values:
            total.append(key)
            return(total)
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

So close! The return statement is indented too far. In this position, the function will return after the first match. To fix it, the return should align with the for statement.

Abdulkadir Kollere
Abdulkadir Kollere
1,723 Points

That worked. I often get in trouble with the indentations. Thanks alot!!