I have two lists, lhs and rhs, which are equal in length. I wish to create a function to transform lhs and rhs into a list of rules, myDesiredList:
lhs = {1, 2, 4, 5, 7};
rhs = {"01", "02", "03", "04", "05"};
myDesiredList = {1 -> "01", 2 -> "02", 4 -> "03", 5 -> "04", 7 -> "05"};
Here's a solution using Map, Rule (i.e., ->), and Transpose:
method1 = Map[#[[1]] -> #[[2]] &, Transpose[{lhs, rhs}]];
method1 == myDesiredList
(* True *)
Is there a simpler or more elegant way to do obtain myDesiredList from lhs and rhs?
By the way, a list of rules can be converted into an association simply by wrapping Association around it:
Association[myDesiredList]
(* <|1 -> "01", 2 -> "02", 4 -> "03", 5 -> "04", 7 -> "05"|> *)