Suppose there are two lists a = {a1, a2, a3} and b = {b1, b2, b3}, and I want to write an assignment statement to make a1=b1,a2=b2,a3=b3 which only refers to a and b:
Thread[a = b]
But it only makes a={b1,b2,b3}. Using := (SetDelayed) instead of = doesn’t work either.
Any solution? Thanks.
I think the
Threadonly works on “explicit” lists; the variables need to be expanded before being operated on.After some experimentation, this works for me:
a = {a1, a2, a3}; b = {b1, b2, b3}; Thread[Set[Evaluate@a, Evaluate@b]]; {a1, a2, a3}You could also write
Thread[Evaluate@a = Evaluate@b]; just depends whichever you find more readable.