Getting symmetric difference of elements of sets in Julia – symdiff() and symdiff!() Methods
The symdiff() is an inbuilt function in julia which is used to construct the symmetric difference of elements in the passed in sets.
Syntax: symdiff(s, itrs…)
Parameters:
- s: Specified first set.
- itrs: Specified second set.
Returns: It returns the symmetric difference of elements in the passed in sets.
Example:
Python
# Julia program to illustrate # the use of symdiff() method # Getting the symmetric difference of # elements in the passed in sets. println(symdiff([ 1 , 4 , 6 ], [ 1 , 3 , 5 ])) println(symdiff([ 1 , 2 , 3 , 4 ], [ 0 , 1 , 2 , 3 ])) println(symdiff(unique([ 1 , 2 , 1 ]), unique([ 2 , 1 , 2 ]))) |
Output:
[4, 6, 3, 5] [4, 0] Int64[]
symdiff!():
The symdiff!() is an inbuilt function in julia which is used to construct the symmetric difference of the passed in sets, and overwrite the specified set s with the result.
Syntax:
symdiff!(s::Union{AbstractSet, AbstractVector}, itrs…)
Parameters:
- s: Specified set.
- itrs: Specified iterable.
Returns: It returns the symmetric difference of the passed in sets.
Example:
Python
# Julia program to illustrate # the use of symdiff !() method # Getting the symmetric difference of # elements in the passed in sets and # overwrite s with the result println(symdiff !([ 1 , 4 , 6 ], 1 : 2 )) println(symdiff !([ 1 , 2 , 3 , 4 ], [ 0 , 1 , 2 , 3 ])) println(symdiff !(unique([ 1 , 2 , 1 ]), unique([ 2 , 1 , 2 ]))) |
Output:
Contact Us