Calculate Field with Python

187
1
03-24-2021 04:22 AM
Labels (3)
KalSsin
New Contributor III
uniqueList = []
def isDuplicate(inValue):
  if inValue in uniqueList:
    return 1
  else:
    uniqueList.append(inValue)
    return 0

qqqq.JPG 

0 Kudos
1 Reply
JoshuaBixby
MVP Esteemed Contributor

I suggest using a cursor instead:

from collections import Counter

layer = # name of layer or path to feature class

with arcpy.da.UpdateCursor(layer, ["NAME", "Field"]) as cur:
    count = Counter(name for name, field in cur)
    cur.reset()
    
    for name, field in cur:
        cur.updateRow([name, 1 if count(name) > 1 else 0])
0 Kudos