Calculating Union and Intersection - Problem Solution
Explore three approaches to return the union and intersection of two sets as a tuple.
Method 1
def solution(set1, set2): return (set1 | set2, set1 & set2)
Using the above code, you can calculate the union and intersection of the given sets set1
and set2
.
Example Usage
Input/Output Example
set1 = {1, 2, 3, 4, 5} set2 = {3, 4, 5, 6, 7} result = solution(set1, set2) print(result) # Output: ({1, 2, 3, 4, 5, 6, 7}, {3, 4, 5})
Lecture
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help