Is there an easy way to remove duplicates of a list of tuples where for the duplicates only the second element is considered? For example when I have the following list:
a = [("a",1),("b",3),("c",4),("d",8),("e",1)]
I want to end up with:
a = [("b",3),("c",4),("d",8),("e",1)]
I doesn't matter if I keep "a" or "e".
Yes, you can use the unique(f, itr) method to do this; it returns the elements of itr where f returns unique values.
julia> unique(x->x[2], a)
4-element Array{Tuple{String,Int64},1}:
("a", 1)
("b", 3)
("c", 4)
("d", 8)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With