4
$\begingroup$

I have the following list:

lis1={{{A3,T3},{A3,T4}},{{A3,T3}},{{A3,T3},{A4,T4},{A3,T1}}}

Which is also accompanied by an Association of:

 assoc = <|A1 -> 10, A2 -> 2, A3 -> 10, A4 -> 10, T1 -> 10, T2 -> 11, 
  T3 -> 10, T4 -> 14|>

If I then do ReplaceAll[lis1,assoc], I get a new list:

lis2={{{10, 10}, {10, 14}}, {{10, 10}}, {{10, 10}, {10, 14}, {10, 10}}}

What I would like to do is use the Pick function and pull out the sublists in lis1 only if their numerical values given by the association are the same. That would yield me the desired list of:

lisfinal={{{A3,T3}},{{A3,T3}},{{A3,T3},{A3,T1}}}

To perform this without any sublists you can use Pick[lis1,Equal@@@(lis1/.assoc)], but I'm having trouble using that same function with multiple sublists present. I've tried both Map and Apply, but I don't think I'm getting the syntax correct.

Edit: I have changed the association values to reflect my question

$\endgroup$
  • 2
    $\begingroup$ ReplaceAll[lis1,assoc] gives {{{6, 12}, {6, 14}}, {{6, 12}}, {{6, 12}, {10, 14}, {6, 10}}}, not {{{10, 10}, {10, 14}}, {{10, 10}}, {{10, 10}, {10, 14}, {10, 10}}} $\endgroup$ – kglr Jun 2 at 19:47
  • $\begingroup$ Sorry about that, I had the wrong association values there, I've edited the post $\endgroup$ – D'Angelo Jun 2 at 20:17
6
$\begingroup$

Try

Pick[lis1, Apply[Equal, lis1 /. assoc, {2}]]
| improve this answer | |
$\endgroup$
4
$\begingroup$

An alternative to Pick, if I understand your parameters:

GatherBy[#, Map[assoc]][[1]] & /@ lis1
{{{A3, T3}}, {{A3, T3}}, {{A3, T3}, {A3, T1}}}
| improve this answer | |
$\endgroup$
1
$\begingroup$
Delete[lis1,Position[lis2, {x_Integer,y_}/;x!=y]]

{{{A3, T3}}, {{A3, T3}}, {{A3, T3}, {A3, T1}}}

Or, independent of lis2

lis1//Delete[#,Position[#/.assoc, {x_Integer,y_}/;x!=y]]&
| improve this answer | |
$\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.