# How can I reduce my code and can I remove word True from the result?

list={{{2, 4, -3}, {3, 5, -1}}, {{2, 4, -3}, {3, 5, 7}}, {{2, 4, -3}, {5,
1, 9}}, {{2, 4, 9}, {3, 5, -1}}, {{2, 4, 9}, {3, 5, 7}}, {{2, 4,
9}, {5, 1, -3}}, {{3, 2, -4}, {5, 1, -3}}, {{3, 2, -4}, {5, 1,
9}}, {{3, 2, -4}, {5, 4, 6}}, {{3, 2, 10}, {5, 1, -3}}, {{3, 2,
10}, {5, 1, 9}}, {{3, 2, 10}, {5, 4, 6}}, {{3, 5, -1}, {6, 2,
7}}, {{3, 5, -1}, {7, 2, 4}}, {{3, 5, 7}, {6, 2, -1}}, {{3, 6,
2}, {5, 1, -3}}, {{3, 6, 2}, {5, 1, 9}}, {{3, 6, 4}, {5,
1, -3}}, {{3, 6, 4}, {5, 1, 9}}, {{5, 1, -3}, {6, 2, -1}}, {{5,
1, -3}, {6, 2, 7}}, {{5, 1, -3}, {7, 2, 4}}, {{5, 1, 9}, {6,
2, -1}}, {{5, 1, 9}, {6, 2, 7}}, {{5, 1, 9}, {7, 2, 4}}}


I want to Select from list an element {pA,pB}so that Mod[pA + pB, 2] == {0, 0, 0}. I tried

Table[{pA, pB} = points;
{pA, pB, Mod[pA + pB, 2] == {0, 0, 0}}, {points, list}];
Cases[list2, {__, True}]


I got

{{{3, 2, -4}, {5, 4, 6}, True}, {{3, 2, 10}, {5, 4, 6}, True}}

Can I reduce my code and can I remove word True to get,

{{{3, 2, -4}, {5, 4, 6}}, {{3, 2, 10}, {5, 4, 6}}}

• As you yourself say, use Select: Select[list, Mod[#[[1]] + #[[2]], 2] == {0, 0, 0} &] – swish Mar 9 '18 at 13:00
• A variation of @swish's solution uses the selection function Mod[Total[#], 2] == {0, 0, 0} &. – J. M.'s torpor Mar 9 '18 at 13:02

Pick is typically faster than Select. On large lists, I would recommend

Pick[list, Total[Mod[Total[list, {2}], 2], {2}], 0]


which is 10 or 20 times faster than these variations.

Select[list, Mod[Total[#], 2] == {0, 0, 0} &]

Cases[list, _?(Total[Mod[Total[#], 2]] == 0 &)]


You can use Nothing:

{{{3, 2, -4}, {5, 4, 6}, True}, {{3, 2, 10}, {5, 4, 6}, True}} /. True -> Nothing

(* {{{3, 2, -4}, {5, 4, 6}}, {{3, 2, 10}, {5, 4, 6}}} *)