0
$\begingroup$

Instead of doing

l1 = {}
l2 = {}

Is there a way to incorporate a loop to make this process faster?

$\endgroup$
2
$\begingroup$

Use an indexed variable

Clear[x]

(x[#] = {}) & /@ Range[5];

x /@ Range[5]

(* {{}, {}, {}, {}, {}} *)
$\endgroup$
0
$\begingroup$

Assuming you are trying to define and set symbols x1..xn to {}

Do[Evaluate@ToExpression["x" <> ToString@i] = {}, {i, 5}];
{x1, x2, x3, x4, x5}
(* {{}, {}, {}, {}, {}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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