I have a feature class layer that comprise of line elements. For my purpose, I needed the start and end point coordinates of each line, so I added new columns with add field and use calculate geometry in ArcGIS Pro to assign the start/end coordinates to each line (below table show the attributes).
What I want to do is that to write a python code that compare lines’ first and end coordinates. Then return a
IDs for those that their start/end points are equal, and append all those as nested lists in a main list. For instance, if object
IDs 2, 5 and 6 have same start and end point, and if object
IDs 8, 12, 15 an 22 have the same condition, the code return a nested list like this:
main_list = [[2, 5, 6], [8, 12, 15, 22]]. Finally, I want to edit the
var column with this outcome. I want
var to be equal to length of each corresponding nested list minus one. For instance for those example above,
var values for object
IDs 2, 5 and 6 will be 2 (length of nested list minus one), and for
IDs 8, 12, 15 and 22 will be 3.
fields = ['ID', 'x_start', 'y_start', 'x_end', 'y_end'] MainList = [] NestedList =  ID = [row for row in arcpy.da.SearchCursor(Redundancy_one, ('ID'))] x_start = [row for row in arcpy.da.SearchCursor(Redundancy_one, ('x_start'))] y_start = [row for row in arcpy.da.SearchCursor(Redundancy_one, ('y_start'))] x_end = [row for row in arcpy.da.SearchCursor(Redundancy_one, ('x_end'))] y_end = [row for row in arcpy.da.SearchCursor(Redundancy_one, ('y_end'))] i = 0 while i<len(ID): with arcpy.da.SearchCursor[Redundancy_one, fields] as cursor: for row in cursor: if x_start == row and y_start == row and x_end == row and y_end == row and ID =! row: NestedList.append(ID) NestedList.append (row) MainList.append(NestedList) NestedList= i +=1