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

Idan shami
Idan shami
13,251 Points

set math task 2, help please

hi.... I don't understand what I need to do now.... I looked in other answers but I don't understand how they do it, and it's incomplete. also, I don't understand why not just union the all thing and return it... why we cannot do it? help please, I really appreciate the community. and one more thing, if I get stuck in some challenge should I continue or wait until I completed the task? (;

    "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(parameter):
    c_list = []
    for course in COURSES:
        if COURSES[course] & parameter:
    return c_list

def covers_all(set1):
    all_topics = []
    for course in COURSES:
        if COURSES & set1:
    return all_topics
Gilbert Craig
Gilbert Craig
2,102 Points

Perhaps reviewing the video would help. COURSES contains pairs of keys and values so your for loops should reflect this. The video also covered how sets 'Interact' Review 'issubset' in python docs for covers_all.

You will also need to consider ing COURSES.items() to access the topics in your for loops

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

In the first task, a simple overlap of sets using intersection & is sufficient. Task 2 is looking for the more restrictive proper subset of course. For this use issubset or <= notation.

Also, the if statement in covers_all should probably use course not COURSES

Idan shami
Idan shami
13,251 Points

I solved it yesterday but thanks anyway (: but I have some questions:

  1. I didn't understand what issubset does.
  2. I didn't understand what super set and sub set mean.... can you explain them and give an example? Thanks ! have a good day (:
Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

The set objects have lots of methods. The method someset.issubset(other):

set <= other
Test whether every element in the set is in other.

set < other
Test whether the set is a proper subset of other, that is, set <= other and set != other

Superset - contains all the elements of some other set (a subset) plus other elements

Subset - is contained entirely within another set (it's superset)

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Intersection only shows if two sets overlap in any way. Task 2 is needs to check if one set completely over laps the other.