2 回答

TA贡献1834条经验 获得超8个赞
您可以使用出租车几何:
def manhattan(as_, b):
threshold = 4
for a in as_:
p1, p2 = a
q1, q2 = b
dist = abs(p1 - q1) + abs(p2 - q2)
if dist <= threshold:
return b
else:
continue
t = list(filter(lambda i: manhattan(listA, i), listB))
[(0, 3), (0, 4), (4, 10)]
或者
from operator import truth
t = list(filter(truth, (manhattan(listA, i) for i in listB)))

TA贡献2041条经验 获得超4个赞
这是我认为你正在寻找的
A= [(1,6),(3,10),(4,1),(0,5)]
B = [(0,3),(0,4),(30,1),(4,10)]
result=[x for x in B if any(x[0]-2<=a[0]<=x[0]+2 and x[1]-2<=a[1]<=x[1]+2 for a in A)]
print(result)
输出 :
[(0, 3), (0, 4), (4, 10)]
添加回答
举报