# Export list entries under a certain condition without using loops

I have a big list that contains many 3D- chains (set of points) and for each of them a polynomial. So the structure of my list is for example

list= {{m^2 + l^2 - 1, {{x1, y1, z1}, {x2, y2, z2}, ...}}, {l^3, {{x'1, y'1, z'1}, ...}}


and so on.

Now I want to export all chains in a separate file which have either p1 or p2 as their polynomial. So in a if-loop the syntax would be like

If[
list[[i]][[1]] === (p1 or p2),
Export["list_i.txt", multilist[[i]][[2]], "Table", "FieldSeparators" -> " "]
]


I want to avoid using loops, and I also don't know how to include the current value of i in the loop in the filename of the export-file.

Does anyone know how to do this without loops? Thanks a lot!

• Have you tried Select and then Map Export on the preselected chains? – BlacKow May 5 '16 at 16:05

selected = Select[list, First[#] === p1 || First[#] === p2 &];

It would be best, however, if you had actual examples of your list and of the polynomials p1 and p2 for us to test our code on.