3
$\begingroup$

I have a nested list:

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

and would like to select only those lists out of it with two items in it:

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

How could this be achieved?

$\endgroup$
  • 1
    $\begingroup$ Select[lst, Length@# == 2 &] (see Select) $\endgroup$ – kglr Jun 19 '17 at 21:49
  • 1
    $\begingroup$ Cases[lst,{_,_}] $\endgroup$ – andre314 Jun 19 '17 at 21:58
2
$\begingroup$

Input

data = {{{1, 2, 3, 4, 5, 6}}, {{1}, {2, 3, 4, 5, 6}}, {{1, 2}, {3}, {4, 5, 6}}};

Select[data, Length @ # == 2 &] 

Output

{{{1}, {2, 3, 4, 5, 6}}}
$\endgroup$
  • $\begingroup$ thanks! very helpful $\endgroup$ – Wafram Jul 14 '17 at 18:46
  • $\begingroup$ You are welcome :) $\endgroup$ – e.doroskevic Jul 15 '17 at 22:33

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.