Basic Python
union, intersection
Naranjito
2022. 3. 10. 20:47
- union
It contains all the elements contained in both sets. (A ⋃ B)
a={'red', 'green', 'blue'}
b=set(['red', 'yellow', 'orange'])
a_union_b=a.union(b)
print(a_union_b)
>>>
{'blue', 'green', 'red', 'yellow', 'orange'}
- intersection
It contains only the elements that are in both sets.
a_intersec_b=a.intersection(b)
print(a_intersec_b)
>>>
{'red'}