This is a scaled down code of what I'm working with:
assoc1 = <|"T1" -> 1, "T2" -> 2, "T3" -> 3, "Z1" -> 4|>
lis1 = {{{"T1","T2","T1"}, {"Z1","T3","T2"}, {"T1","T1","Z1"}, {"T2","T3","T3"}}}
lis2 = lis1 /. assoc1
What I'm trying to do is to filter through lis1
and make a few different lists which fit the criteria in which numbers in designated spots within sublists of lis2
have the same value . For example let's say I wanted to create another list which is made up of pulled sublists from lis1
in which the numbers in position 1 and position 3 of any sublist given by lis2
had the same value, this would give us a new list of:
newlis1 = {{{"T1","T2","T1"}}}
Likewise, let's say I wanted to only pull out sublists in which the first two or last two numbers within a sublist were equal, this would give two new lists respectively:
newlis2= {{{"T1","T1","Z1"}}}
and newlis3 = {{{"T2","T3","T3"}}}
Is there a generic way to do this? I was thinking maybe using DeleteCases
but I hadn't gotten anything along those lines to work.
newlis1 = List /@ Cases[lis1, {a_, _, a_}, All]
and{newlis2, newlise3} = List /@ Cases[lis1, {a_, a_, _} | {_, a_, a_}, All]
? $\endgroup$