2
$\begingroup$

Let's consider the following list

data = {{1}, {}, {1,1,1}, {1,1}, {1}, {1,1}, {1}, {2,1,1}, {3,1}, {3,2,1}, {}}

As we can see, some rows have 0, other 1, other 2, etc elements. How can I pick only those rows which contain three elements?

$\endgroup$
2
$\begingroup$
Select[Length@ # == 3&] @ data

{{1, 1, 1}, {2, 1, 1}, {3, 2, 1}}

Also

Cases[{_,_,_}] @ data

Cases[_?(Length @ # == 3&)] @ data

Pick[data, 3 - Length /@ data, 0]

Pick[data, Unitize[Length /@ data -3], 0]
$\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.