Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. m = [[False, False, False, False],
  2.      [True, False, False, True],
  3.      [False, False, False, True],
  4.      [False, False, False, False],
  5.      [False, False, False, False]]
  6. def neighbours(m, pos):
  7.     a = []
  8.     for i in range (len(m)):
  9.         for j in range (len(m[i])):
  10.             if pos == (i,j):
  11.                 if i > 0 and m[i - 1][j] == True:
  12.                     a.append((i-1,j))
  13.                 if i < len(m) - 1 and m[i + 1][j] == True:
  14.                     a.append((i+1,j))
  15.                 if j > 0 and m[i][j - 1] == True:
  16.                     a.append((i,j - 1))
  17.                 if j < len(m[i]) - 1 and m[i][j + 1] == True:
  18.                         a.append((i,j + 1))
  19.     return a
  20.     #print(a)
  21. b = neighbours(m, (0, 0))
  22. b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement