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$
2
  • 2
    $\begingroup$ Select[lst, Length@# == 2 &] (see Select) $\endgroup$
    – kglr
    Jun 19, 2017 at 21:49
  • 2
    $\begingroup$ Cases[lst,{_,_}] $\endgroup$
    – andre314
    Jun 19, 2017 at 21:58

1 Answer 1

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$
2
  • $\begingroup$ thanks! very helpful $\endgroup$
    – Wafram
    Jul 14, 2017 at 18:46
  • $\begingroup$ You are welcome :) $\endgroup$ Jul 15, 2017 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.