Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • $\begingroup$ there is another option: Values@AssociationThread[myNewList -> myList] $\endgroup$ Commented Jan 19, 2016 at 14:13
  • $\begingroup$ @garej, That one takes the cake timewise. For a larger list, it's hard to see how it chooses which of the elements in myList to keep for the various duplicates, but I think it does it correctly. All the other methods choose the first corresponding entry, making it easy to check visually on a small list that it did the right thing. I can add it here, or you can add it to your answer, on a large list it's the fastest method. $\endgroup$ Commented Jan 19, 2016 at 14:35
  • $\begingroup$ @JasonB it always keeps the last one per key, isn't it? It's like <|1 -> old, 1->new|>. $\endgroup$ Commented Jan 19, 2016 at 15:10
  • $\begingroup$ @Kuba, that's it, the old one is replaced by the new one. $\endgroup$ Commented Jan 19, 2016 at 15:11
  • 1
    $\begingroup$ If order is important you can Reverse both the old and new lists, perform the operation, then Reverse the result, and you'll have the original order. $\endgroup$ Commented Jan 20, 2016 at 0:41