- 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'}
'Basic Python' 카테고리의 다른 글
title, items (0) | 2022.06.29 |
---|---|
tqdm (0) | 2022.04.07 |
swapcase (0) | 2021.12.22 |
@ (0) | 2021.11.15 |
itertools.islice, chain, isinstance (0) | 2021.05.25 |