Hi,

maybe this helps:

@doc "Return a Dict of all elements in sequence which contains a vector of 
their positions." ->
function unique_positions(sequence)
  table = Dict()
  for (index,elt) in enumerate(sequence)
    if !haskey(table, elt)
      table[elt] = []
    end
    push!(get(table,elt,nothing), index)
  end
  table
end

julia> unique_positions(A)
Dict{Any,Any} with 4 entries:
  "c" => Any[3]
  "b" => Any[2,6]
  "a" => Any[1,4]
  "d" => Any[5]

(The Dict type can be refined with parameters).

Best,

Tamas

On Wed, Apr 29 2015, Ján Dolinský <[email protected]> wrote:

> Hi,
>
> I am trying to find all duplicates in an iterable collection e.g. of
> strings.
>
> A = String["a", "b", "c", "a", "d", "b"]
>
> Function unique(A) will return the unique elements. How can I find the
> remaining duplicates ? I tried setdiff(A, unique(A)) but it works in a
> different way.
>
> Thanks ,
> Jan

Reply via email to