Skip to main content
added 43 characters in body
Source Link
Henrik Schumacher
  • 112.9k
  • 7
  • 197
  • 339
list1 = {{A, 12}, {B, 10}, {C, 4}, {D, 2}}; list2 = {{A, 4}, {D, 11}, {B, 5}, {C, 1}}; idx = Lookup[   AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],   list2[[All, 1]]   ]; list2[[idx]]result = list2; result[[idx]] = list2; result 

{{A, 4}, {B, 5}, {C, 1}, {D, 11}}

idx = Lookup[ AssociationThread[list1[[All, 1]] -> Range[Length[list1]]], list2[[All, 1]] ]; list2[[idx]] 

{{A, 4}, {B, 5}, {C, 1}}

list1 = {{A, 12}, {B, 10}, {C, 4}, {D, 2}}; list2 = {{A, 4}, {D, 11}, {B, 5}, {C, 1}}; idx = Lookup[   AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],   list2[[All, 1]]   ]; result = list2; result[[idx]] = list2; result 

{{A, 4}, {B, 5}, {C, 1}, {D, 11}}

deleted 10 characters in body
Source Link
Henrik Schumacher
  • 112.9k
  • 7
  • 197
  • 339
idx = Lookup[ AssociationThread[list1[[All, 1]] -> Range[Length[list1[[All, 1]]]]]Range[Length[list1]]], list2[[All, 1]] ]; list2[[idx]] 

{{A, 4}, {B, 5}, {C, 1}}

idx = Lookup[ AssociationThread[list1[[All, 1]] -> Range[Length[list1[[All, 1]]]]], list2[[All, 1]] ]; list2[[idx]] 

{{A, 4}, {B, 5}, {C, 1}}

idx = Lookup[ AssociationThread[list1[[All, 1]] -> Range[Length[list1]]], list2[[All, 1]] ]; list2[[idx]] 

{{A, 4}, {B, 5}, {C, 1}}

Source Link
Henrik Schumacher
  • 112.9k
  • 7
  • 197
  • 339

idx = Lookup[ AssociationThread[list1[[All, 1]] -> Range[Length[list1[[All, 1]]]]], list2[[All, 1]] ]; list2[[idx]] 

{{A, 4}, {B, 5}, {C, 1}}