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 trialIdan shami
13,251 Pointsset 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? (;
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(parameter):
c_list = []
for course in COURSES:
if COURSES[course] & parameter:
c_list.append(course)
return c_list
def covers_all(set1):
all_topics = []
for course in COURSES:
if COURSES & set1:
all_topics.append(course)
return all_topics
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsIn 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
13,251 PointsI solved it yesterday but thanks anyway (: but I have some questions:
- I didn't understand what issubset does.
- 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
Treehouse Moderator 68,441 PointsThe set
objects have lots of methods.
The method someset.issubset(other):
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)
wan muhammad najmie wan sabri
1,943 Pointsiām just curious..why wont intersection works?
Chris Freeman
Treehouse Moderator 68,441 PointsIntersection only shows if two sets overlap in any way. Task 2 is needs to check if one set completely over laps the other.
Gilbert Craig
2,102 PointsGilbert Craig
2,102 PointsPerhaps 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