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

Create a new function named covers_all that takes a single set as an argument. Return the names of all of the courses, i

Need help on what I am doing wrong.


    "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(python):
    list = []
    for course, value in COURSES.items():
        if value.intersection(python):
    return list 

def covers_all(1set):
    list = []
    for course, value in COURSES.items():
        if len(set(1set) & (COURSES[keys])): 
             return list

2 Answers

Robert Stefanic
Robert Stefanic
35,170 Points

Without checking the logic too much, I see a few issues here that need to be fixed.

  1. A variable in Python cannot start with a number. So the argument name that you've defined in covers_all needs to be changed to a valid variable name (you can just change 1set to set1).

  2. On this line:

    if len(set(1set) & (COURSES[keys])): 

    There's an extra ) before your colon.

  3. Your return statement is inside of your if statement. So as soon as something matches this condition if len(set(1set) & (COURSES[keys])):, it's going to append the current course that was checked, and return the list with just one element.

  4. Where did [keys] come from in (COURSES[keys])? This may be a Python thing that I'm unaware of, but did you mean for it to be values which was defined in your for loop?

Go ahead and make those minor changes, and see if you can't figure it out from there. :)

Eduardo Valencia
Eduardo Valencia
12,444 Points

When you used the "&" symbol in the following line, you are checking if both of them evaluate to True, and then checking the length of the boolean value.

if len(set(1set) & (COURSES[keys])):

This is not what you need. Think about the challenge instructions. It is asking you the following:

  1. To look into the given set of topics, and to intersect that with each course value in COURSES (like you did in your "covers" function).
  2. To check that all items in the given set of topics are in the course value. The intersection function gives you back the items it found in common between the two sets. You have both the results and the items you wanted. What do you think you need to do to know if the items you wanted (the given set of topics) is equal to the results? If that is true, then what do you think you need to do next with the name of the course?