I have two lists of rules:
aa = {1 -> {5, 2}, 3 -> {2, 2}, 4 -> {2, 3}, 5 -> {1, 2}, 6 -> {1, 1},
7 -> {2, 1}, 8 -> {1, 1}};
newVnames = {1 -> "EGW", 2 -> "MA2", 3 -> "HLT", 4 -> "AGF",
5 -> "WHS", 6 -> "TSC", 7 -> "CO12", 8 -> "FIN"};
List aa
has 7 elements, while newVnames
has 8 (unbalanced lists). This implies that we need first to drop one irrelevant rule from newVnames
which is 2->"MA2"
and then replace the remaining elements in newVnames
in ONLY to the first
elements (before ->
) of aa
.
For example, {1->"EGW"}
in newVnames
should be replaced in the first
element of the first
element in aa
to get:
EGW->{5,2}
I tried various versions of:
Table[aa[[i]][[1]] /. newVnames[[i]], {i, Length[aa]}]
But I could not get what I want to. Please advise me a code
for this task.
Normal@KeyMap[Association[newVnames]]@Association[aa]
? $\endgroup$Normal@KeyMap[ReplaceAll[newVnames]]@Association[aa]
? $\endgroup$SubsetMap[ReplaceAll[newVnames], aa, {All, 1}]
$\endgroup$SubsetMap[ReplaceAll@newVnames, {All, 1}]@aa
$\endgroup$