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 trialAdam Tyler
14,865 PointsCovers
This works inside workspaces, I have checked by giving covers several different arguments. But I can not pass the code challenge. Is something for a very specific case wrong which I just haven't picked up on in manually testing it?
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(top):
#see if union is same as key, if so, add to list
courses = []
for i in COURSES.keys():
if top.union(COURSES[i]) == COURSES[i]:
courses.append(i)
else:
continue
return courses
3 Answers
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Adam,
Have you tried the empty set? Your function should return an empty list in that case.
Cheers
Alex
Steven Parker
231,236 PointsAn "overlap" would e a case where two sets had one or more elements in common, But an equality between one set and the union of of it and another only indicates that the first doesn't contain anything that is not in the second. It doesn't indicate that they have any elements in common.
An intersection might be a better way to test for "overlap".
Adam Tyler
14,865 PointsBut it works in workspace, the idea was that if the union of the two sets is the same as the second set, then the first set is a subset of the second and therefore, as its a subset, they have elements in common and therefore it should work?
Steven Parker
231,236 PointsIt wouldn't have to be a subset, it could just be empty. The union would still match the other set, but they would have no elements in common.
Alex Koumparos
Python Development Techdegree Student 36,887 PointsWhen you say it works in workspace, did you check the empty set?
In set theory, the union of the empty set and set A is set A; the intersection of the empty set and set A is the empty set. Accordingly, this would be a a specific case where your code, which uses union, would produce a different answer from what the challenge wants, which is intersection.