在 Julia 中获取集合元素的对称差异 – symdiff() 和 symdiff!() 方法
symdiff()是 julia 中的一个内置函数,用于构造传入集合中元素的对称差异。
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.
例子:
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])))
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])))
输出:
[4, 6, 3, 5]
[4, 0]
Int64[]
符号差异!():
symdiff!()是 julia 中的一个内置函数,用于构造传入集合的对称差,并用结果覆盖指定的集合s 。
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.
例子:
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])))
输出: