Hi Ian,
You could also give this script a try as well.
import arcpy
ws = arcpy.env.workspace = r"<workspace path>"
fc= "<feature class>"
field_LN = "<Last Name field>"
field_UID = "UID"
#Create field list
fields = arcpy.ListFields(fc, "", "")
#Create an empty set to be populated with unique last names
seen = set()
#Loop through fields and perform a search cursor to find the unique last names and then
for field in fields:
with arcpy.da.SearchCursor(fc, field_LN) as sCur:
for row in sCur:
items = row[0]
#Add unique last names to the set()
seen.add(items)
#Convert the set to a list
uniqueValues = list(seen)
#Loop through unique value list
for item in uniqueValues:
#Perform an update cursor that updates a unique value field to that of the last name's index in the unique values list
with arcpy.da.UpdateCursor(fc, [field_LN, field_UID]) as iCur:
for row in iCur:
if row[0] == item:
row[1] = uniqueValues.index(item)
if row[0] == item:
row[1] = uniqueValues.index(item)
if row[0] == item:
row[1] = uniqueValues.index(item)
iCur.updateRow(row)
Hopefully this will help you achieve your desired result.
- Jacob