Set Operation


1. 합집합(union)

  • set.union(set1, set2)
  • set1 | set2
set1 = {1,2,3,4}
set2 = {3,4,5,6}

set1 | set2
=> {1,2,3,4,5,6}

2. 교집합(intersection)

  • set.intersection(set1, set2)
  • set1 & set2
set1 = {1,2,3,4}
set2 = {3,4,5,6}

set1 & set2
=> {3,4}

3. 차집합(difference)

  • set.difference(set1, set2)\
  • set1 - set2
set1 = {1,2,3,4}
set2 = {3,4,5,6}

set1 - set2
=> {1,2}

4. 대칭차집합(symmetric difference)

  • set.symmetric_difference(set1, set2)\
  • set1 ^ set2
set1 = {1,2,3,4}
set2 = {3,4,5,6}

set1 ^ set2
=> {1,2,5,6}