Getting exclusive elements of a set in Julia – setdiff() and setdiff!() Methods
The setdiff() is an inbuilt function in julia which is used to returns the elements which are in first set but not in second set.
Syntax:
setdiff(s, itrs...)
Parameters:
- s: Specified first set.
- itrs: Specified second set.
Returns: It returns the elements which are in first set but not in second set.
Example:
Python
println(setdiff([ 1 , 4 , 6 ], [ 1 , 3 , 5 ]))
println(setdiff([ 1 , 2 , 3 , 4 ], [ 0 , 1 , 2 , 3 ]))
println(setdiff( Set ([ 2 , 3 ]), BitSet([ 3 , 4 ])))
|
Output:
setdiff!()
The setdiff!() is an inbuilt function in julia which is used to remove each element of set s which are also in the specified iterable.
Syntax:
setdiff !(s, itrs...)
Parameters:
- s: Specified first set.
- itrs: Specified iterable.
Returns: It returns the remaining elements of the set s after removal.
Example:
Python
A = Set ([ 1 , 2 , 3 , 4 ]);
setdiff !(A, 1 : 2 : 3 );
println(A)
B = Set ([ 1 , 2 , 3 , 4 , 5 , 6 ]);
setdiff !(B, 1 : 3 : 5 );
println(B)
|
Output:
Set([4, 2])
Set([2, 3, 5, 6])
Last Updated :
24 Feb, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...