I have a large list of arrays of the following form
{{{0, 0, 0}, 1}, {{2, 2, 2}, 0}, {{2, 2, 0}, 0}, {{2, 2, -2},
0}, {{2, 0, 2}, 0}, {{2, 0, 0}, 1}, {{2, 0, -2}, 0}, {{2, -2, 2},
0}, {{2, -2, 0}, 0}, {{2, -2, -2}, 0}}
with the second entity in each element is either 0 or 1. I need to create a do loop that search within each array for those elements with second entity equals 1 and return the result as a new array with all other elements eliminated. If none of the array element satisfy this requirement I need the result to be returned as 0. For example for the above array I want to get the result as
{{0, 0, 0}, {2, 0, 0}}
because these two elements have second entity equals 1.. How can I do that?
Cases[]
orSelect[]
. Alternatively, useGatherBy[]
orGroupBy[]
and pick out what you need. $\endgroup$ – J. M.'s ennui♦ Jun 22 '16 at 16:21Cases[lst, {a_List, 1} :> a]
$\endgroup$ – march Jun 22 '16 at 16:22