0
$\begingroup$

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.

$\endgroup$
4
$\begingroup$

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)&)}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.