# Export many lists without using loops

I have a Mathematica function that creates a RandomWalk chain of length l, by generating random points on the unit sphere and then using the Accumulate function. So the output of this function is a list like {{x1,y1,z1},{x2,y2,z2},...}. Then I use another function to create N of these lists, so the output of this function is something like {{{x1,y1,z1},{x2,y2,z2},...},{x1,y1,z1},...}} and so on. How can I now export each of these N lists in a separate output file without using loops? Idealy I would have a folder at the end with "list1.txt", "list2.txt", .."listN.txt" .

For one list I used something like

Export["test.txt", list, "Table", "FieldSeparators" -> " "]


• Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– user9660
May 4, 2016 at 17:31

I think MapIndexed would help you here. Try something like the following:

MapIndexed[
Export["list" <> ToString[First@#2] <> ".txt", #1, "Table", "FieldSeparators" -> " "] &,
yourmultilist
]

• Thank you! That worked. Do you also know a solution to the other problem I have? I have another function which calculates a knot invariant of a RandomWalk chain and I only want to export those lists which have a polynom p1 or p2. Is there a way to add only lists which fulful that condition to my multilist which is generated by the "Table"- syntax? The alternative would be using a loop where I generate a list, check if it fulfuls the condition, but loops are much slower. Thank you! May 5, 2016 at 6:57
• @Guest23232 since this second problem you mention is quite separate from the first one, it would be best if you asked in another question. That way more people will see it. You should also include an example of the conditions you want to enforce. Generally speaking, however, you should consider Select or Cases as a possible starting point. May 5, 2016 at 12:39

This creates some random sample data lists

lists = RandomInteger[{0, 9}, {3, 3, 3}];
n = 0;
Map[Export[n=n+1;"list"<>ToString[n]<>".txt",#,"Table","FieldSeparators"->" "]&, lists]


exports three files list1.txt, list2.txt and list3.txt