Transforming input text into code
This looks like a case where an Association[]
is more appropriate:
as = AssociationThread @@ Transpose[{{"l", {1, 0}}, {"a", {1, 1}}, {"j", {0, 1, 0}},
{"u", {0, 1, 1}}, {"e", {0, 0}}}]
Then you can do this:
StringJoin[Map[IntegerString, Lookup[as, Characters["lea"]], {2}]]
"100011"
ClearAll[code]
code = StringReplace[# -> StringRiffle[#2, ""] & @@@ #]&;
Example:
list = {{"l", {1, 0}}, {"a", {1, 1}}, {"j", {0, 1, 0}}, {"u", {0, 1, 1}}, {"e", {0, 0}}};
code[list]["lea"]
"100011"
I like J.M.'s solution. But since there is in Mathematica at least 10 ways to do the same thing, I thought to have a go at it
code = {{"l", {1, 0}}, {"a", {1, 1}}, {"j", {0, 1, 0}}, {"u", {0, 1, 1}}, {"e", {0, 0}}};
word = "ltea";
let = Characters[word];
StringJoin@Flatten[Cases[code, {x_, y__} /;
StringMatchQ[x, #] :> (ToString /@ y)] & /@ let]