Skip to content

Instantly share code, notes, and snippets.

@nickyfoto
Created October 14, 2019 15:17
Show Gist options
  • Save nickyfoto/d4459c51b5dfe1b02018777c6b39dc30 to your computer and use it in GitHub Desktop.
Save nickyfoto/d4459c51b5dfe1b02018777c6b39dc30 to your computer and use it in GitHub Desktop.
Python set operation
# https://www.geeksforgeeks.org/python-set-operations-union-intersection-difference-symmetric-difference/
A = {0, 2, 4, 6, 8}
B = {1, 2, 3, 4, 5}
# union
print("Union :", A | B)
# intersection
print("Intersection :", A & B)
# difference
print("Difference A - B:", A - B)
print("Difference B - A:", B - A)
# symmetric difference
print("Symmetric difference :", A ^ B)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment