I have two arrays which have the contents to a NxN matrix.
N=3
x=[1 1 0 2]
y=[1 1 2 0]
I am trying to check for the corner indices (i.e., [0,0], [0,2], [2,0] and [2,2] in this case). But I'm having a confusion regarding the if
statement in this case.
for i in range(len(x)):
if x[i]!=0 or x[i]!=N-1 and y[i]!=0 or y[i]!=N-1:
print(x[i],y[i])
#random code...
If I use this above code, then all the contents of x
and y
print. But if I use:
v=[0,N-1]
for i in range(len(x)):
if x[i] not in v and y[i] not in v:
print(x[i],y[i])
#random code...
It gives the correct output. Don't these two mean the same thing? Please clarify this query.
Aucun commentaire:
Enregistrer un commentaire