3
$\begingroup$

I have a list.

{{1, 2, 3, 6, 6}, {1, 2, 4, 6, 6}, {1, 2, 5, 8, 8}, {1, 2, 6, 8,8}, {1, 2, 
7, 14, 10}}

Now I want to get those #1[[-1]]==#2[[-1]] && #1[[-2]]==#2[[-2]]

I will get

{ {{1, 2, 3, 6, 6}, {1, 2, 4, 6, 6}} , {{1, 2, 5, 8, 8}, {1, 2, 6, 8,8}} }

Subsets can do it. But since my data is huge, my memory isn't big enough to hold.

$\endgroup$
7
$\begingroup$

Is this ok?

Select[GatherBy[l, #[[{-2, -1}]] &], Length[#] > 1 &]

{{{1, 2, 3, 6, 6}, {1, 2, 4, 6, 6}}, {{1, 2, 5, 8, 8}, {1, 2, 6, 8, 8}}}

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