Apart from the for(:) loop at (2) to iterate over all elements of the list and read the number of…