I'm trying to get the most common character from a matrix but instead I'm only getting the most common from the last entered row
R = int(input("Enter the number of rows:"))
C = int(input("Enter the number of columns:"))
matrix = []
print("Enter the elements rowwise:")
for i in range(R):
a=[]
for j in range(C):
a.append((input()))
matrix.append(a)
for i in range(R):
for j in range(C):
print(matrix[i][j], end = " ")
print()
from collections import Counter
count = Counter(a)
print(count.most_common())
output:
Enter the number of rows:3
Enter the number of columns:3
Enter the elements rowwise:
a
a
a
e
e
d
c
c
a
a a a
e e d
c c a
[('c', 2), ('a', 1)]