Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Sets Set Math

Nader Alharbi
Nader Alharbi
2,253 Points

My code gives the correct results, but i still receive error message.

Hello there,

I wrote the code for this task and tested it in my python interpreter and it works perfectly, but when i tried to submit my answer it gives me error for some reason which is kinda weird.

Also, if there is a better way other than comparison to an empty set, i would to learn it. Thank you.

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_all(title):
    list_courses = []
    for course_dictionary in COURSES:
        if title - COURSES[course_dictionary] == set():
            list_courses.append(course_dictionary)
    return list_courses

1 Answer

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Nader Alharbi. You are very close and you are right, in the python interpreter, it passes but not in the challenge, the reason is that because the challenge asking overlap in other words intersection() or &. The method what you used is difference() or -. Of course, you don't need the comparison as well, == set(). Also, double check the naming of the covers function, only in the second half of the challenge you need to name it like covers_all. I hope this will help you out in the first half, the second part it's not so different from the first just read carefully the instructions. Happy coding!

Nader Alharbi
Nader Alharbi
2,253 Points

Sorry if i was not clear on this, I already passed part one with intersection and this code is for part 2 which i am stuck on.

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

The second part is not so different from the first, just a different method should be used. On the second quiz, you need to invert what is in the if statement, you looking for subset. Also, don't forget to keep the first function, the covers. I hope this will help you to figure out. Happy coding.

Nader Alharbi
Nader Alharbi
2,253 Points

Hahaha, you were right. My function was correct. All i had to do is just add the function from part 1 (covers).

I passed the question, but i still don't understand one thing, how can i remove the checking for empty set in my if condition? i want to be coding in the best way not just pass questions with unnecessary codes

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

You mean

if title - COURSES[course_dictionary] == set():   <--- this set() part?

My solution was this

if COURSES[course_dictionary] >= title: