# How to apply Length in all elements

I want to apply Length in each element from a list. For example:

My list is: {1,{2,3},{4,5,6}}

How to apply Length in each element of this list?

Length[{1}]
Length[{2,3}]
Length[{4,5,6}]


I have tried to use Thread, but doesn't works:

In[235]:= Thread[Length[{1, {2, 3}, {4, 5, 6}}]]

Out[235]= 3


The result that I want is some like:

1
2
3


Which is the number of elements in each element.

• What in your opinion is the Length of 1? You can use Map: Map[Length, {1, {2, 3}, {4, 5, 6}}]. Jan 22, 2019 at 17:45

If[AtomQ @ #, 1, Length @ #] & /@ {1, {2, 3}, {4, 5, 6}}


{1, 2, 3}

If the input list does not contain {} (thanks: @corey979), you can also use:

Length /@ {1, {2, 3}, {4, 5, 6}} /. 0 -> 1
(* or Map[Length]@{1, {2, 3}, {4, 5, 6}} /. 0 -> 1 *)


{1, 2, 3}

• Note that the first approach fails on {1, {2, 3}, {}, {4, 5, 6}}. The second, however, works well. Jan 22, 2019 at 18:24
• @corey979, very good point.
– kglr
Jan 22, 2019 at 18:30

Introduce ChartingpadList to make a list for your element..

Length@*ChartingpadList /@ {1, {2, 3}, {4, 5, 6}}


{1, 2, 3}

• Brilliant. Care to elaborate more on ChartingpadList? Jan 22, 2019 at 18:22

A mildly adjusted version of the nice Charting answer by yode is to apply a list to each element and flatten:

Length@Flatten@List@#&/@{1, {2, 3}, {4, 5, 6}}
`