I have a feature class and I need to renumber from 1 and increase by 1 for a group of features. To do that, I need to define these groups (based on atributes of a field) and for each group make an update cursor. My problem is that in my code, just the first group of features are updated and the others not. Where is my mistake?
This is what I have today
and this is what I want
My code:
import arcpy
lyrName = r"C:\Users\Moshe\Documents\ArcGIS\Default.gdb\D1"
Layer = "Layer"
RefName = "RefName"
startNumber = 1
listValue = []
with arcpy.da.SearchCursor(lyrName, Layer) as cursor:
for row in cursor:
value = row[0]
listValue.append(row[0])
list = list(dict.fromkeys(listValue))
print(list)
Layer2 = "Layer"
RefName2 = "RefName"
with arcpy.da.UpdateCursor(lyrName, [RefName2, Layer2]) as cursor2:
for i in list:
print (i)
for row2 in cursor2:
if row2[1] in str(i):
row2[0] = startNumber
startNumber = startNumber + 1
cursor2.updateRow(row2)
print "updated row {}".format(row2[0])
startNumber = 1


dictionary– Vince Jun 18 '21 at 14:10