I want to create a dispatch list (list of rules to replace parameters) from a standard list.

I have an equation which depends on a, b, c, d. I want to pass lots of different values from a data set.

Let's say I have the list:

In[1]  :=   parameters 
Out[1] :=   {a, b, c, d}

And get some values on an array:

In[2] := dataset[[1]]
Out[2] := {10, -0.4, 3, -7}

I would like to create a list of rules using the variables

{a-> 10, b-> -0.4, c-> 3, d-> -7}

How could I do it?

I found this answer, but I think it just may serve as a basis to get to solve my question. From a list to a list of rules . Nevertheless, I think that making explicit this approach may come handy for new Mathemathica users unfamiliar with the coding.


Using From a list to a list of rules as a basis I was able to construct the list of rules.

However it is important to know that the cited answer, creates nested lists of rules.

listOfRules = dataset[[1]] // Thread[parameters -> #] &


Thread[ parameters -> dataset[[1]] ] 

I could also suggest MapThread as in

MapThread[Rule[#1, #2] &, {parameters, dataset[[1]]}]

There are certainly many ways to achieve your objective.

parameters = {a, b, c, d};
data1 = {10, -0.4, 3, -7};

keyvalDispatch[keys_, values_] := Inner[Rule, keys, Transpose@values, List]

keyvalDispatch[parameters, data1]
(* {a -> 10, b -> -0.4, c -> 3, d -> -7} *)

Same as this answer from an earlier thread.


Not the answer you're looking for? Browse other questions tagged or ask your own question.