# How to multi-Set a group of lists?

I have a group of lists, for example:

lists = RandomInteger[10, {100, 2}]

{{6, 7}, {7, 4}, {3, 3}, ....}


Now, I want to multi-set as follow:

ls1={6,7};
ls2={7,4};
,,,,
lsX=lists[[X]]


How to do that by a simple way?

Thanks.

UPDATE:

How about lsX but not ls[X]?

I have tried to generate a list of names:

names=ToExpression["ls" <> ToString@# & /@ Range]


How to multi set then?

lists = RandomInteger[10, {100, 2}];
Table[ls[i] = lists[[i]], {i, 1, Length @ lists}];


OR

Do[ls[i] = lists[[i]], {i, 1, Length @ lists}];


OR

For[i = 1, i <= Length @ lists, i++, ls[i] = lists[[i]]]


Now you can individually get their values e.g ls, ls etc.

EDIT

If you really want ls1, ls2 ... then the following should do it:

Table[Evaluate[Symbol["ls" <> ToString[i]]] = lists[[i]], {i, 1, Length @ lists}];


Now you can use ls1 , ls2, etc

• How about lsX but not ls[X]? – bushiwo Oct 25 '13 at 3:27
• @bushiwo. You're better off doing it this way in Mathematica. Unless there's a specific reason you want it that way. – RunnyKine Oct 25 '13 at 3:29
• @bushiwo. See my edit. That's what you want right? – RunnyKine Oct 25 '13 at 3:35
• Could you tell me why I can't use my names function in my UPDATE? – bushiwo Oct 25 '13 at 3:43
• @bushiwo. All you've done is create a bunch of Mathematica expressions (in this case symbols) using ToExpression. Now you have to assign them values individually, which defeats the purpose. In my updated answer, I create and assign the values at once. Is that not what you want? – RunnyKine Oct 25 '13 at 3:48

Not that I think this particularly useful, but it does exactly what you asked for:

lists = RandomInteger[10, {5, 2}];

MapIndexed[(Evaluate[Symbol["ls" <> ToString[#2[]]]] = #1) &, lists];

{ls1, ls2, ls3, ls4, ls5} == lists
(*
True
*)


I believe this will achieve your aim. I have used "l" rather than "ls" but you can change.

MapThread[
Set[#1, #2] &, {Symbol /@ (Table["l" <> ToString[j], {j, 100}]),
lists}]


Set @@@ Transpose[{names, lists}]


This is a reasonable application of Map, which uses the shortcut /@

lists = RandomInteger[10, {100, 2}];
(ls[#] = lists[[#]]) & /@ Range[Length[lists]]


As requested, ls is the first of the elements in list, ls the second, etc. As suggested by Belisarius, this can also be done more succinctly using MapIndexed

MapIndexed[(all[#2[]] = #1) &, lists]

• I was referring to MapIndexed[(all[#2[]] = #1) &, lists] – Dr. belisarius Oct 25 '13 at 3:48
• Very nice. I guess this means that I was reinventing MapIndexed -- don't think I've ever used it before. – bill s Oct 25 '13 at 4:01