Search code examples
julia

how to use set operations in julia language


I want to use set() as in python in Julia. Is it possible to do so? If yes, please provide an example using the following python code

set(A) - set(B)

Solution

  • The relevant functionality is explained in the docs. While you can still use -, it's been deprecated:

    julia> A = [1,2,3]; B = [2,3,4];
    
    julia> Set(A) - Set(B)
    WARNING: a::Set - b::Set is deprecated, use setdiff(a,b) instead.
     in - at deprecated.jl:26
    Set{Int32}({1})
    
    julia> setdiff(A, B)
    1-element Array{Int32,1}:
     1
    
    julia> setdiff(Set(A), Set(B))
    Set{Int32}({1})
    

    Note: we can use setlike ops on arrays directly, in which case they're order-preserving.