hello I want to combine multiple for loops into one loop to make my code less complex. the loop iterates over the elements in a list of lists and add +1 for every correct value.
so let's say i have
ink = 0
mouse = 0
rat = 0
matrix = [
['', 'article1.txt', 'article2.txt', 'article3.txt'], ['ink', 2, 3, 0], ['mouse', 0, 2, 1], ['rat', 0, 0, 1]]
and
for line in matrix[1:2]:
for i in line[1:]:
if i > 0:
ink = ink + 1
for line in matrix[2:3]:
for i in line[1:]:
if i > 0:
mouse = mouse + 1
for line in matrix[3:4]:
for i in line[1:]:
if i > 0:
rat = rat + 1
I'd want this to become one loop or atleast some shorter code that automatically does this, even if there would be more rows and columns in the matrix.
for row in matrix[1:]: for col in row[1:]:...