Mapping string into integers
For the specific numbering in OP, you can also use LetterNumber
:
LetterNumber[l]
{{2, 3, 4}, {5, 2}, {1, 2, 4, 5}}
The following gives you a "reversed" version of your association, with keys and values flipped:
l1 = <|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>;
lookup = First /@ PositionIndex@l1
(* <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4, "e" -> 5|> *)
You can then use ReplaceAll
(/.
) to do the replacement:
l = {{"b", "c", "d"}, {"e", "b"}, {"a", "b", "d", "e"}};
l /. lookup
(* {{2, 3, 4}, {5, 2}, {1, 2, 4, 5}} *)
Alternatives
Other possible solutions for creating lookup
:
lookup = <|Reverse /@ Normal@l1|>
lookup = Reverse /@ Normal@l1 (* doesn't need to be an association *)
l /. Reverse /@ Normal[l1]
(* {{2, 3, 4}, {5, 2}, {1, 2, 4, 5}} *)
or
l /. AssociationMap[Reverse, l1]
(* {{2, 3, 4}, {5, 2}, {1, 2, 4, 5}} *)