Skip to content

Instantly share code, notes, and snippets.

@amarinelli
Created January 25, 2016 16:40
Show Gist options
  • Save amarinelli/ae903d5b57ed8ee42bce to your computer and use it in GitHub Desktop.
Save amarinelli/ae903d5b57ed8ee42bce to your computer and use it in GitHub Desktop.
Simply list duplicates values for a field using arcpy
table_rows = []
duplicates = []
layer = "Springs"
fields = ["OBJECTID", "FCode"]
with arcpy.da.SearchCursor(layer, fields) as cursor:
for row in cursor:
if row[1] in table_rows:
duplicates.append(row[0])
else:
table_rows.append(row[1])
if duplicates:
print "\n{} duplicate(s) found (listed by {})\n".format(len(duplicates), fields[0])
print duplicates
# Do stuff with duplicates
else:
print "No duplicates found - all values in {} are unique".format(fields[1])
@amarinelli
Copy link
Author

The code should in the Python window of ArcMap (update values on lines 4, 5).

If needed for use in a standalone script, add:

import arcpy
arcpy.env.workspace = "<path to geodatabase>"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment