import random def counterEfficient(scores, sizeRow, sizeCol, size): counterList=[0]*(size) for i in range(sizeRow): for j in range(sizeCol): counterList[scores[i][j]]+=1 return counterList def make_list(scores, sizeRow, sizeCol, num): for i in range(sizeRow): for j in range(sizeCol): scores[i][j]=random.randint(0,num) return scores def printMatrix(scores, sizeRow, sizeCol): for i in range(sizeRow): print(scores[i]) def main(): sizeR=int(input("enter row size ")) sizeC=int(input("enter column size ")) my_list =[[0 for i in range(sizeC)]for j in range(sizeR)] num=int(input("enter the range of random numbers ")) my_list=make_list(my_list, sizeR, sizeC, num) print("original list is") printMatrix(my_list, sizeR, sizeC) #function call #pay attention, the last parameter is num + 1 #for example, if the range of random numbers is 3 #so the items in the list are 0, 1, 2, and 3 #then the size of counter list is 4 #since we need to count how many times each number appears #in the list cList=counterEfficient(my_list, sizeR, sizeC, num+1) print("list of counters ") print(cList) main()