I'm trying to Reap/Sow elements of a list into separate sub-lists. In this toy example, I want evens in one list, odds in the other. But whichever sub-list d[[1]] happened to belong in, that sub-list comes first in Reap's output. If I wanted the even list to come first, I have to retest and reorder the sub-lists after Reap is finished. That isn't so bad when (as in the example) there are only two sub-lists, but in a bigger problem I have 20+ attributes with corresponding sub-lists! Is there a way to control what order Reap puts sub-lists in?
This works but is clunky and inefficient:
d = RandomInteger[100, 100]; (* Synthetic data *)
r = Reap[Do[If[EvenQ[d[[i]]], Sow[d[[i]], 1], Sow[d[[i]], 2]], {i, 1, Length[d]}]][[2]];
If[! EvenQ[r[[1, 1]]], r = {r[[2]], r[[1]]}]; (* Annoying that I have to do this to make the even list come first. *)
r
Reap
?Reap[ Sow[5, b]; Sow[4, a]; Sow[7, c]; Sow[8, b]; , {a, b, c, d}]
for example $\endgroup$