🛠️ToolsShed

집합 계산기

두 집합의 합집합, 교집합, 차집합, 대칭차집합을 계산합니다.

자주 묻는 질문

코드 구현

# Set operations in Python
A = {1, 2, 3, 4, 5}
B = {3, 4, 5, 6, 7}

# Union: all elements in A or B
union = A | B
print(union)           # {1, 2, 3, 4, 5, 6, 7}

# Intersection: elements in both A and B
intersection = A & B
print(intersection)    # {3, 4, 5}

# Difference: elements in A but not B
diff_AB = A - B
print(diff_AB)         # {1, 2}

diff_BA = B - A
print(diff_BA)         # {6, 7}

# Symmetric difference: in A or B but not both
sym_diff = A ^ B
print(sym_diff)        # {1, 2, 6, 7}

# Subset checks
print({1, 2}.issubset(A))    # True
print(A.issuperset({1, 2}))  # True

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.