# How delete a pair from a list of pairs if the last element of the pair is complex?

Suppose we have a list of pairs for example $\{\{1,2\},\{-1,2+3i\},\{4,6i\},\{3,4\}\}$

How delete the pairs from a list of pairs if the last element of the pair is complex?

Such that in the above case the second and third elements get removed.

You can try this

DeleteCases[{{1, 2}, {-1, 2 + 3 I}, {4, 6 I}, {3, 4}}, {_, _Complex}]
(* {{1, 2}, {3, 4}} *)


For the other cases you can use pattern, built-in functions or user-functions. For example, try to delete elements with negative numbers in the second place

data = {{1, 2}, {-1, -3}, {4, 6}, {3, -4}};
DeleteCases[data, {_, _?((# < 0)&)}]

list = {{1, 2}, {-1, 2 + 3 I}, {4, 6 I}, {3, 4}};


Using RealValuedNumberQ (new in 13.3)

Cases[list, {__?RealValuedNumberQ}]


{{1, 2}, {3, 4}}

Using Pick and FreeQ

Pick[list, FreeQ[_Complex] /@ list]


{{1, 2}, {3, 4}}

Another variant using Pick and ReIm:

list = {{1, 2}, {-1, 2 + 3 I}, {4, 6 I}, {3, 4}};

Pick[#, AllTrue[#, Last@ReIm[#] == 0 &] & /@ #] &@list

(*{{1, 2}, {3, 4}}*)


Or using Select and RealValuedNumberQ:

Select[list, MatchQ[Total@#, _?RealValuedNumberQ] &]

(* (*{{1, 2}, {3, 4}}*)*)


Or using Delete and Position:

Delete[#, Position[{a_, b_Complex}]@#] &@list

(* (*{{1, 2}, {3, 4}}*)*)