So on a list I need to check if 'z' is in the same row as the case selected and return True, but if something is on the way for example 'x' it returns False. I made a code but the problem it has is that if there is two 'z's and the one on the left is blocked by an 'x' but the other one is not, it returns False but it should be True. It works fine for the other cases. Hope you get me, I'm pretty bad explaining these things.
def row(lst,i,j):
c = 0
if 'z' not in lst[i]:
c += 1
else:
for n in range(0,len(lst[i])):
if lst[i][n] == 'z' and n > j:
for m in range(j,n):
if lst[i][m] == 'x':
c += 1
else:
c = 0
break
if lst[i][n] == 'z' and j > n:
for m in range(n,j):
if lst[i][m] == 'x':
c += 1
else:
c = 0
break
if c > 0:
return False
elif c == 0:
return True
I don't really know what exactly does 'break' here but it works The list I use is:
lst = [['_','_','_','_','_'],['z','x','_','_','z'],['_','_','x','_','_']]
and the case I'm checking is lst[1][2].
['_','x','_','_','z']
returns True, there is a 'z' in the row.
['_','x','_','x','z']
returns False, z is being blocked
['z','x','_','x','z']
returns False
['z','x','_','_','z']
PROBLEM: should return True