# How to rewrite a nested loop with Reap and Sow [closed]

I was wondering if anyone know how to rewrite the following nested loop but using Reap and Sow. I need to reduce the execution time. Thank you.

list = {};
AbsoluteTiming[
Do[
AppendTo[list, {}];
If[i > 10,
AppendTo[list[[i]], {}];
]
, {i, 1, 10^4}]
]


## closed as unclear what you're asking by Oleksandr R., Kuba♦, Öskå, Karsten 7., Mr.Wizard♦Jan 26 '15 at 7:40

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• I have no idea what you are trying to accomplish. But you can get the same answer like this: list = ConstantArray[{{}}, 10^4]; list[[1 ;; 10]] = {}; in far less time. – bill s Jan 16 '15 at 3:57

Your question is not well posed because it is predicated on a misconception that Reap and Sow are the appropriate tools to do what you wish to accomplish. bill s, rightly ignoring the constraint you place on the solution, has given a method which is both fast and simple.

list = {};
First @ AbsoluteTiming[
Do[
AppendTo[list, {}];
If[i > 10, AppendTo[list[[i]], {}];],
{i, 1, 10^4}]]


gives 0.711651 seconds. bill s' code

First @ AbsoluteTiming[
list = ConstantArray[{{}}, 10^4]; list[[1 ;; 10]] = {};]


gives 0.000102 seconds. Both methods build the same list.