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

sets.py

This is doing what I want in workspace not sure why it's not passing...

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(value):
    for objects in COURSES.items():
        if len(value & objects[1]) >= 1:
            return [objects[0]]

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

I agree that your code is perfect for the single answer case they supplied!

I think they want you to interpret that the solution to be that the function will find multiple courses which contain the same topic.

Example:

courses({'strings'}) should return ['Python Basics', 'Java Basics', 'PHP Basics', 'Ruby Basics']

currently, your code returns the first ['Python Basics'] which is correct, but misses the others.

Your code is well written, so all you need to do is to add a "memory" list of courses you detected.

Keep up the good work! Python is an amazing language that has nearly infinite possibilities!

def covers(value):
    courses = [] # will allow us to remember each course object that contained the topic
    for objects in COURSES.items():
        if len(value & objects[1]) >= 1:
           courses.append(objects[0]) # append (save) the course name to the course list
    return courses