# How to get the first value of the duplicate in this association list

I have the following association list. I want to get the first value of the duplicate item, but only the last value. What should I do?

    Merge[{<|a -> 1, b -> 2, b -> 3, a -> 2, c -> 4, d -> 5,
c -> 2|>}, Last]
Merge[{<|a -> 1, b -> 2, b -> 3, a -> 2, c -> 4, d -> 5,
c -> 2|>}, First](*The result I want is <|a -> 1, b -> 2, c -> 4, d -> 5|>*)


As Rohit Namjoshi said, can I first convert the relationship list to the normal list {a -> 1, b -> 2, b -> 3, a -> 2, c -> 4, d -> 5, c -> 2} and then try to achieve the goal?

• An Association cannot have duplicate keys.<|a -> 1, b -> 2, b -> 3, a -> 2, c -> 4, d -> 5, c -> 2|> evaluates to <|a -> 2, b -> 3, c -> 2, d -> 5|>. Commented Feb 25, 2020 at 4:28
• association data struct is like a dictionary in other languages. There is no "first" or "second" or "last", etc.. in association. i.e. there is no order implied. So what you say find the "last" item, then the question itself is not well posed. You can convert association to normal list using the command Normal. Commented Feb 25, 2020 at 5:06
• @Nasser: Well, there is an ordering of the keys in an association (see KeySort) and you can do asso[[2]] for getting the value of the second key. But doing this is typically asking for trouble... =) Commented Feb 25, 2020 at 7:43
• @HenrikSchumacher I was thinking of the values itself. From this "Items in a dictionary are accessed by key and are unordered." And then read that reference.wolfram.com/language/guide/Associations.html says "Associations provide generalizations of .... dictionaries," So that is what I meant. I was thinking of the data itself (values) not keys. That is what I understood by question above when it said "duplicate item". Commented Feb 25, 2020 at 8:04
• @Nasser I meant my comment more as an addition to your comment, not as criticism. Commented Feb 25, 2020 at 8:42

Merge[{a -> 1, b -> 2, b -> 3, a -> 2, c -> 4, d -> 5, c -> 2}, First]

<|a -> 1, b -> 2, c -> 4, d -> 5|>