I want to implement an operation on the following list:
For a given arbitrary length of list $\{a1,a2,a3,a4,a5,a6,a7,a8,\cdots\}$, the task is to find the number of zeros and their position(s). So I want my output to be:
{number of zeros, {position(s) of zero(s)}
For example, $\{0,1,2,-1,0,1,3,0\}$, I want to count $0$; so zero happens twice and the position of zero to be in 1st, 5th, 8th position, i.e., I want my output as $\{3, \{1, 5 ,8\}\}$.
First of all, I know how to count the zeros:
list1={0,1,2,-1,0,1,3,0};
Count[list1, x_ /; x == 0]
Then it gives 3
as an output. Maybe I can find the position(s) by using the loop explicitly, but I think there is a simpler way to implement it in Mathematica.
{Length@#, Flatten@#} &@Position[list1 = {0, 1, 2, -1, 0, 1, 3, 0}, 0]
$\endgroup$