📜  在 Julia 中获取集合元素的对称差异 – symdiff() 和 symdiff!() 方法

📅  最后修改于: 2022-05-13 01:54:37.502000             🧑  作者: Mango

在 Julia 中获取集合元素的对称差异 – symdiff() 和 symdiff!() 方法

symdiff()是 julia 中的一个内置函数,用于构造传入集合中元素的对称差异。

例子:

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

例子:

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])))

输出: