Question about using an association within Replace
.
If I have an association which contains symbols like so:
dict = <|Subscript[r, 1] -> 1, Subscript[r, 2] -> 2|>
and I do some operation using these variables for e.g.
lst = f[#1[[1]], #[[2]]] & /@ {{Subscript[r, 1], 1},{Subscript[r, 2],2}}
Then, if I try to use the association defined in dict
within Replace
, it doesn't seem to recognize the variable.
lst /. f[x_, y_] -> dict[x]
and throws a KeyAbsent
error:
{Missing["KeyAbsent", Subscript[r, 1]],
Missing["KeyAbsent", Subscript[r, 2]]}
Here's a minimal working example to reproduce the error:
Block[{dict, lst},
dict = <|Subscript[r, 1] -> 1, Subscript[r, 2] -> 2|>;
lst = f[#1[[1]], #[[2]]] & /@ {{Subscript[r, 1], 1},{Subscript[r,2], 2}};
lst /. f[x_, y_] -> dict[x]
]
Why is the output not {1,2}
?