Rather than storing marks in the grid, you should create an addition list which stores the x,y positions of each mark, then loop over that to check if each pair satisfies the condition. So something like this:
import math
points = [(0,0), (5,10), (100,200)]
for n, point_n in enumerate(points):
for point_m in points[n+1:]:
if math.dist(point_n, point_m) < 5:
print('distance less than 5!')
Note math.dist
is only available in Python3.8 and higher, you will have to code the distance function yourself in lower versions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…