Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Set symmetric Using Python Set symmetric_difference() Method

# Set X
X = {1, 2, 3}

# Set Y
Y = {2, 3, 4}

# Set Z
Z = {2, 3, 4}

print("Symmetric difference between X & Y", X.symmetric_difference(Y))
print("Symmetric difference between Y & Z", Y.symmetric_difference(Z))
print("Symmetric difference between X & X", X.symmetric_difference(X))
Comment

symmetric_difference() Function of sets in python

# The symmetric_difference() function can be used to create a new set containing
# the symmetric differences of two sets.

mySet = {1, 2, 3, 4}
mySet2 = {3, 4, 5, 6}
mySet3 = mySet.symmetric_difference(mySet2)
print(mySet3)

# Output:
# {1, 2, 5, 6}
Comment

How to Get the Symmetric Difference of Sets in Python

firstSet = {2, 3, 4, 5}

secondSet = {1, 3, 5, 7}

print(firstSet ^ secondSet)
# {1, 2, 4, 7}
Comment

PREVIOUS NEXT
Code Example
Python :: geopandas with postgis 
Python :: column of lists pandas 
Python :: how to play audio in python using pygame 
Python :: @foreach 1 numper 
Python :: python dictionary get vs setdefault 
Python :: python while variable is not 
Python :: search for list of strings in pandas column 
Python :: date to timestamp python 
Python :: joblib example 
Python :: multiple logger instances populating single log python 
Python :: size of int in python 
Python :: open multiple urls 
Python :: python dlib 
Python :: for in print 
Python :: python keyerror 
Python :: how to create copy of all objects in list python 
Python :: pythagoras theorem formula 
Python :: eval in python 
Python :: create 20 char with python 
Python :: boto3 python s3 
Python :: python load file with multiple jsons 
Python :: how to add hyperlink in jupyter notebook 
Python :: python equivalent of R sample function 
Python :: s.cookie.set python 
Python :: functools.cached_property objects in python 
Python :: .lstrip() 
Python :: pandas filter by dictionary 
Python :: connect with database python 
Python :: random.randint(0,20) + pyrthon 
Python :: keras.callbacks.History 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =