def func(arr, a, b):
for elem1 in range(len(arr)):
for elem2 in range(len(arr[elem1])):
if arr[elem1][elem2] == a:
onePositionA = arr.index(arr[elem1])
twoPositionA = arr[elem1].index(arr[elem1][elem2])
elif arr[elem1][elem2] == b:
onePositionB = arr.index(arr[elem1])
twoPositionB = arr[elem1].index(arr[elem1][elem2])
if abs(onePositionA - onePositionB) <= 1 and abs(twoPositionA - twoPositionB) <= 1:
return True
else:
return False