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

Kaisar Turysbek
Kaisar Turysbek
9,480 Points

Python Collections - Set Math 2-nd Code Challenge Not Passing

"Couldnt find "covers" "-Error

    "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(x):
    for key in COURSES:
        if len(x&COURSES[key])>0:
    return a    
def cover_all(x):
    for key in COURSES:
        if len(x&COURSES[key])==len(x):
    return a        

task: Great work! OK, let's create something a bit more refined. Create a new function named covers_all that takes a single set as an argument. Return the names of all of the courses, in a list, where all of the topics in the supplied set are covered. For example, covers_all({"conditions", "input"}) would return ["Python Basics", "Ruby Basics"]. Java Basics and PHP Basics would be exclude because they don't include both of those topics.

5 Answers

Ken LaRose
Ken LaRose
Python Web Development Techdegree Student 21,982 Points

The error "couldn't find covers" is odd because it's right there! Maybe it's because you need spaces before and after the function? Maybe it's because of the line

if len(x&COURSES[key])>0

what are you trying to do with the '&'? I do not think you can do that with a str and a set. Maybe try

if x in COURSES[key]:

instead? I'm just kind of guessing at what you're after. Please provide more detail if that doesn't help you out!

seong lee
seong lee
4,503 Points

ken larose it should be and not an in

So when it said write a set as an argument I put my function as def covers_all({"strings", "input"}): The reason I used those words is because those keywords are in all courses of the list. Then I was gonna use the intersection function so it could call all the courses. Is that correct ? And how would I type that code out. Thats my biggest problem I dont know how to actually write the code out and how to write it out correctly. All advice welcomed

def cover_all(x): a=[] for key in COURSES: if len(x&COURSES[key])==len(x): a.append(key) return a