Count digits present in each element of a given Matrix | Python3 program for the above approach ; Function to count the number of digits in each element of the given matrix ; Traverse each row of arr [ ] [ ] ; Traverse each column of arr [ ] [ ] ; Store the current matrix element ; Count the number of digits ; Print the result ; Driver Code ; Given matrix
from math import floor , log10 NEW_LINE M = 3 NEW_LINE N = 3 NEW_LINE def countDigit ( arr ) : NEW_LINE INDENT for i in range ( M ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT X = arr [ i ] [ j ] NEW_LINE d = floor ( log10 ( X ) * 1.0 ) + 1 NEW_LINE print ( d , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ [ 27 , 173 , 5 ] , [ 21 , 6 , 624 ] , [ 5 , 321 , 49 ] ] NEW_LINE countDigit ( arr ) NEW_LINE DEDENT