The code below (which comes from one of my training courses) does the key part of what you are describing. Basically, it takes an input polygon feature class (testFC) on which you have run Polygon Neighbors to create a table (NEIGHBOURS). The feature class has an extra field called NEIGHBOURS (Text, 100) added.
What the code does is to:
- Make a Table View from the table which is needed to be able Select By Attribute on it later
- Open an Update Cursor (uCursor) on the polygon feature class to access the ID and empty NEIGHBOURS fields
- For each polygon it selects the corresponding rows in the NEIGHBOUR table and opens a Search Cursor (sCursor) on them
- Use the Search Cursor to build up a comma separated list of the IDs for each neighbouring polygon
- Strip any commas from either end of the comma separated list
- Write that list into the NEIGHBOURS field
with arcpy.da.UpdateCursor(r"C:\test.gdb\testFC",["ID","NEIGHBOURS"]) as uCursor:
for uRow in uCursor:
arcpy.SelectLayerByAttribute_management("NEIGHBOURS_View","NEW_SELECTION","src_ID = " + "'" + uRow + "'")
with arcpy.da.SearchCursor("NEIGHBOURS_View","nbr_ID") as sCursor:
neighbours = ""
for sRow in sCursor:
neighbours = neighbours + "," + sRow
uRow = neighbours.strip(",")