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
Jacques Plomion
2,446 PointsDifference between set.intersection(otherset) and set.issubset(otherset)
Hi all,
I have this script for the question on sets:
def covers(topics):
result_list = []
for course, course_topics in COURSES.items():
#if topics.issubset(course_topics):
if topics.intersection(course_topics):
result_list.append(course)
return result_list
when I use issubset, I get an error when I submit my response, but when I use intersection, it works fine. Yet, the ouput is the same in both cases.
Any insights for me?
Thanks
Jack
1 Answer
Dave StSomeWhere
19,870 PointsYour results are the same because you didn't try enough test cases. The challenge is looking for "Overlap" which is intersection - and will return all courses that contain any of the passed values. Subset returns the courses that contain all the values.
If you test with:
print(covers({"Python", "functions"}))
# intersection returns - both have functions
['Python Basics', 'Ruby Basics']
# issubset returns - only Python Basics has Python and functions
['Python Basics']
Jacques Plomion
2,446 PointsJacques Plomion
2,446 PointsThat makes sense. Thanks Dave!