2
$\begingroup$

Suppose I have the following list,

t = {{"e:r", "a", "p", "z"}, {"r:e", "a", "l", "o", "t", "y", 
    "z"}, {"j", "o", "z"}};

I want to go through it and pick the elements that have "e:r" or "r:e" they are the same in fact I just put it this way so the final code would be applied to any orderless system. To do this I made the following:

mod = {{"e:r"}};
tmp = Table[SubsetQ[mod, t[[i]]], {i, Length[t]}];
make = Pick[t, tmp];

But this does not work, am I doing something wrong here?

UPDATE: I can use

Select[ContainsAny@{"e:r", "r:e"}]@t

But how can I just use "r:e" or "e:r" and the program would understand they are the same?

$\endgroup$
2
$\begingroup$
cc = Total[ToCharacterCode["e:r"]];
Pick[t, 1 - Unitize[Total[ToCharacterCode[t[[All, 1]]], {2}] - cc], 1]

{{"e:r", "a", "p", "z"}, {"r:e", "a", "l", "o", "t", "y", "z"}}

$\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.