我需要打印矩阵的坐标,其对应的行和列仅为零
例子:
3 3
1 0 0
0 0 0
1 0 0
在上面的例子中,在坐标(1,1)处,行和列为零(0),我需要打印所有行和列为零的冠状体。(比如需要办理入住手续
加号
)
我的代码:
r,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(r)]
for i in range(len(l)):
for j in range(0,len(l[i])):
if sum(l[i])==0 and sum(l[j])==0:
print(i,j)
我的代码适用于上面提到的输入,但适用于下面提到的输入不适用为什么??
输入:
6 13
1 0 1 0 1 0 1 0 1 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1 0 1 0 1 0
所需输出:
1 13
2 13
3 13
4 13
我的输出:
1 1
1 2
1 3
1 4
Traceback (most recent call last):
File "main.py", line 5, in <module>
if sum(l[i])==0 and sum(l[j])==0:
IndexError: list index out of range
我犯了什么错误?请帮帮我!!