Suppose I have a list
l = {a, b, c, d, e, f....}
I would like to remove one of each pair {x,y}
if some function check[x,y]
returns x
or y
(or do nothing for that particular pair if the function returns {}
). The order of the list is important. For example, if
check[c,e] === c;
check[a,f] === f;
and check
on any other combination is empty, the final list should be
{a, b, d, e, ...}
I know how to write a for loop and do index-based removal, but is it a slicker way to do it using Mathematica's list manipulation functions?
EDIT:
The check
function should be non-overlapping in my usage, but in case if there is problematic overlap, say
check[a,e] === a;
check[a,f] === f;
both e and f should remain, since after removal of a (assuming position of a is earlier than f), there is no pair that can be formed with {a,f}.
Check
is intended to be your own, custom function but that name is already in use. User symbols should start with lower case letters. $\endgroup$check[a,b] == a
andcheck[a,d] == a
? Is it sufficient to removea
? Should the secondcheck
be performed at all? $\endgroup$f
is removed and nota
-- should the element that is not returned be removed? $\endgroup$check
of course; question again edited for consistency. (It proves that I should go to bed instead...) $\endgroup$