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 :: How To Remove Elements From a Set using discard() function in python 
Python :: A Python program to demonstrate inheritance 
Python :: python null check optional 
Python :: box plot seaborn advance python 
Python :: opencv minimum of two images python 
Python :: Unable to locate package python-obexftp 
Python :: python Fibonacci series up to n 
Python :: program to print areas in python 
Python :: Draw GFG Geeks For Geeks Logo using Python and Turtle 
Python :: Python List Note 
Python :: how to clear formatting in python 
Python :: Example of inheritance and constructor in subclass 
Python :: Create New Entry Into Table Django 
Python :: python http server onliner 
Python :: how i make viribal inside a string in python 
Python :: list comperhension condition in python 
Python :: python decorator generator to list 
Python :: Check if a Key is Already Present in a Dictionary 
Python :: Using CGI with Python and HTML forms 
Python :: non venomous snakes 
Python :: how to input a string character into a numpy zeros imatrix n python 
Python :: isat in panadas datframe 
Python :: File "demo_indentation_test.py", line 2 print("Five is greater than two!") ^ IndentationError: expected an indented block 
Python :: distplot for 2 columns 
Python :: python codes and answers cheat code pdf 
Python :: all possibilities of 0 and 1 
Python :: Reading from a file way03 
Python :: Python String Membership 
Python :: pandas replace not working 
Python :: create new column with first character of string pyspark 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =