# Selecting all the elements of different length that contain only numbers

If I have a list of lists with different lengths:

{{1, 2, 3}, {1}, {1, 2, 3, 4}, {x}, {1, x}, {2}, {2, 3}}


How can I extract all the sub-lists with no symbols:

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


There must be an easy way to do this but I can't find it. Unfortunately, I'm not so good with Mathematica to be able to modify similar cases that I found(for example Link1 and Link2) to the problem at hand.

Cases[{{1, 2, 3}, {1}, {1, 2, 3, 4}, {x}, {1, x}, {2}, {2, 3}}, {__?NumericQ}]

• Or 3 underscores if empty lists should also be kept. Commented Mar 17, 2016 at 21:42
• Perfect! Thank you. Commented Mar 17, 2016 at 21:44
• Or DeleteCases[ {{1, 2, 3}, {1}, {1, 2, 3, 4}, {x}, {1, x}, {2}, {2, 3}}, {___, _Symbol, ___}]
– xyz
Commented Mar 18, 2016 at 1:58

Another approach is to use VectorQ:

lis = {{1, 2, 3}, {1}, {1, 2, 3, 4}, {x}, {1, x}, {2}, {2, 3}};
Select[lis, VectorQ[#, NumericQ] &]

(* {{1, 2, 3}, {1}, {1, 2, 3, 4}, {2}, {2, 3}} *)


Variations:

Select[lis, AllTrue[#, NumericQ] &]


I think @march's answer is probably the best way. Here's another for giggles...

Select[{{1, 2, 3}, {1}, {1, 2, 3, 4}, {x}, {1, x}, {2}, {2, 3}}, ! MemberQ[#, _Symbol] &]

• Interesting. What is the name of that _Symbol part? I want to search for other properties that have the same usage. Commented Mar 17, 2016 at 23:24
• @BehzadNazari That's shortcut for Blank[Symbol] which is a pattern match for a certain Head. Head[x] (if x isn't defined) evaluates to Symbol. Try Head /@ {x, 1.0, 1, "test"} for examples.
– kale
Commented Mar 18, 2016 at 2:10