I was wondering how I would compare two 2-dim lists by their location. For instance, I have two 2-dim lists with 0’s and 1’s ,and I want to create a function that would return True if a 1 is in the same location in both lists.
List1=[[0,0,0],
[1,0,0],
[0,0,1]]
List1=[[0,0,0],
[1,0,0],
[0,0,0]]
Here is what I started with, but I am not sure how to continue.
def collide(a,b):
for x in range(3):
for y in range(3):
collide(List1, List2)
Any hints? I was thinking
if a[x][y]==1 and b[x][y]==1:
return True
but that probably isn’t correct.
That looks fine to me, although you don’t account for the two entries being 0 as well.
You might also want to use the actual length of the lists. So instead
That assumes the lists will have the same size.
Make sure that you also return false at the end of the function (since it wouldn’t have gotten to that line if there were a collision)