# Name a list with Table

I am struggling to find a way to assign a value from a list to names from another pre-defined list with Table[].

names = {first, second, third}

numbers = {{1, 1}, {2, 2}, {3, 3}}


What I want is:

first = {1, 1}
second = {2, 2}
third = {3, 3}


so that {1, 1} is stored in first etc.

I tried the following:

namelists = Table[(names[[i]]) = (numbers[[i]]), {i, Length[names]}];


In this case, namelists[[1]] = {1, 1}, however first does not store any information...

• If you are not set on using Table then MapThread[Set, {names, numbers}] Dec 23, 2019 at 12:44

Clear[first, second, third]
names = {first, second, third}
numbers = {{1, 1}, {2, 2}, {3, 3}}
Table[Evaluate[names[[i]]] = numbers[[i]], {i, 3}]
first
second
third

• Since you can make multiple assignments at the same time, you don't need the Table: the "vectorized" Evaluate@names = numbers will work too. Dec 23, 2019 at 15:50
Clear[first, second, third]

names = {first, second, third};
numbers = {{1, 1}, {2, 2}, {3, 3}};

With[{names = names}, names = numbers];

first


{1, 1}

With the following definitions:

Clear[first, second, third]
names = {first, second, third}
numbers = {{1, 1}, {2, 2}, {3, 3}}


a one-liner approach would be:

Evaluate@names = numbers


You can see how this works using Trace:

Clear[first, second, third]
names = {first, second, third}
numbers = {{1, 1}, {2, 2}, {3, 3}}
Trace[Evaluate@names = numbers]

(* Out:
{{names, {first, second, third}},
{numbers, {{1, 1}, {2, 2}, {3, 3}}},
{first, second, third} = {{1, 1}, {2, 2}, {3, 3}},
{{1, 1}, {2, 2}, {3, 3}}} *)


MapThread works well for this task.

numbers = {{1, 1}, {2, 2}, {3, 3}};
Clear[first, second, third]
names = {first, second, third};

{{1, 1}, {2, 2}, {3, 3}}