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

Thomas McDonnell
Thomas McDonnell
8,212 Points

Any help with this one

I feel think I am greatly over thing this here. The below passes in my ipyhton in terminal but fails here in the challenge workspace. I know it looks terribly un pythonic but I continued down the line solving the issues as I went and just ended up with this. Returning intersections alone gave an un-concatenated list so I concatenated it, which gave a string and than converted it back to a list :)

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):
    intersections = []
    for course in COURSES:
        if COURSES[course] & a == a:
            intersections += course
    courses_covered = "".join(intersections)
    cover = [courses_covered]
    return cover

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

You are being more restrictive than necessary. By using

        if COURSES[course] & a == a:

you are testing that a is a proper subset of course (this is what task 2 will look for in covers_all). For Task 1, a simple overlap is sufficient:

        if COURSES[course] & a:

Additionally, Task 1 is looking for a list to be returned. You already have this in intersections. Return interactions

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