📜  在 Julia 中获取集合的交集 – intersect() 和 intersect!() 方法

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

在 Julia 中获取集合的交集 – intersect() 和 intersect!() 方法

intersect()是 julia 中的内置函数,用于构造指定集合的交集。

句法:

intersect(s, itrs...)

参数:

  • s:指定的第一组。
  • itrs:指定的第二组。

返回:它返回指定集合的构造交集。例子:

Python
# Julia program to illustrate
# the use of intersect() method
  
# Getting the intersection of sets.
println(intersect([1, 4, 6], [1, 3, 5]))
println(intersect([1, 2, 3, 4], [0, 1, 2, 3]))
println(intersect(Set([2, 3]), BitSet([3, 4])))


Python
# Julia program to illustrate
# the use of intersect !() method
  
# Getting the elements which
# intersect all passed in sets.
println(intersect !([1, 4, 6], [1, 3, 5]))
println(intersect !([1, 2, 3, 4], [0, 1, 2, 3]))
println(intersect !(Set([2, 3]), BitSet([3, 4])))


输出:

相交!()

intersect!()是 julia 中的一个内置函数,用于将所有传入的集合相交并用结果覆盖 s。

句法:

intersect!(s::Union{AbstractSet, AbstractVector}, itrs...)

参数:

  • s:指定集合。
  • itrs:指定的迭代器。

返回:它返回与所有传入集合相交的元素。例子:

Python

# Julia program to illustrate
# the use of intersect !() method
  
# Getting the elements which
# intersect all passed in sets.
println(intersect !([1, 4, 6], [1, 3, 5]))
println(intersect !([1, 2, 3, 4], [0, 1, 2, 3]))
println(intersect !(Set([2, 3]), BitSet([3, 4])))

输出: