Try this:
matrix = [[0, 0, 0, 1, 0], [0, 0, 1, 1, 1], [0, 1, 0, 1, 0], [1, 1, 1, 0, 1], [0, 1, 0, 1, 0]]
matrix.sort(key=sum, reverse=True)
print(matrix)
Update:
This is in your expected output form:
matrix = [[0, 0, 0, 1, 0], [0, 0, 1, 1, 1], [0, 1, 0, 1, 0], [1, 1, 1, 0, 1], [0, 1, 0, 1, 0]]
count_ones = [(i + 1, item.count(1)) for i, item in enumerate(matrix)]
count_ones.sort(key=lambda x: x[1], reverse=True)
result = [i[0] for i in count_ones]
print(result)
4
solved Sorting Matrix by row sum [closed]