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$

1 Answer 1

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$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.