Is there a more pythonic way of doing this? I am trying to find the eight neighbours of an integer coordinate lying within an extent. I am interested in reducing its verbosity without sacrificing execution speed.
def fringe8((px, py), (x1, y1, x2, y2)):
f = [(px - 1, py - 1),
(px - 1, py),
(px - 1, py + 1),
(px, py - 1),
(px, py + 1),
(px + 1, py - 1),
(px + 1, py),
(px + 1, py + 1)]
f_inrange = []
for fx, fy in f:
if fx < x1: continue
if fx >= x2: continue
if fy < y1: continue
if fy >= y2: continue
f_inrange.append((fx, fy))
return f_inrange