Created
July 6, 2019 04:58
-
-
Save eyaltrabelsi/f5f4e3a77844f8adec30cfebbb758a7e to your computer and use it in GitHub Desktop.
Python tricks set operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> A = {1, 2, 3, 3} | |
>>> A | |
set([1, 2, 3]) | |
>>> B = {3, 4, 5, 6, 7} | |
>>> B | |
set([3, 4, 5, 6, 7]) | |
>>> A | B | |
set([1, 2, 3, 4, 5, 6, 7]) | |
>>> A & B | |
set([3]) | |
>>> A - B | |
set([1, 2]) | |
>>> B - A | |
set([4, 5, 6, 7]) | |
>>> A ^ B | |
set([1, 2, 4, 5, 6, 7]) | |
>>> (A ^ B) == ((A - B) | (B - A)) | |
True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment