Nearest neighbours of a polygon

I’m new to blender and coding in general. I’m having a hard time figuring out a way to make a list of the closest neighbours to a polygon by checking which polygons that share a vertex with a specific polygon.

assuming you’re doing it via bmesh, it’s pretty simple using link_faces:


# this snippet will create an inclusive set of all neighboring faces of the specified face
def get_nearby_faces(this_face):
    nearby_faces = {}
    for v in this_face.verts:
        nearby_faces.update(v.link_faces)
    return nearby_faces