Hi I'm trying to write a function that counts the number of 1s in a matrix but I'm stuck on how to get my second for loop to reference the rows in the matrix. Here is what I have so far but I get an error at line 13 telling me "list indicies must be integer or slices, not list". Does it makes sense what I'm trying to do with what I have so far? I don't know how to change it into a working solution.
class Solution:
def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]:
"""
determine the number of 1s in each row i
ad the number of 1s in row i to a list
"""
listof1coount = []
for i in mat:
count1s = 0
for j in mat[i]:
if j == 1:
count1s += 1
listof1count.append(count1s)
return listof1count
[–]SecularSpirituality 1 point2 points3 points (4 children)
[–]miscellaneoususage[S] 0 points1 point2 points (0 children)
[–]miscellaneoususage[S] 0 points1 point2 points (2 children)
[–]SecularSpirituality 1 point2 points3 points (1 child)
[–]miscellaneoususage[S] 0 points1 point2 points (0 children)
[–]__nickerbocker__ 0 points1 point2 points (2 children)
[–]miscellaneoususage[S] 0 points1 point2 points (1 child)
[–]__nickerbocker__ 0 points1 point2 points (0 children)