Created
January 25, 2016 16:40
-
-
Save amarinelli/ae903d5b57ed8ee42bce to your computer and use it in GitHub Desktop.
Simply list duplicates values for a field using arcpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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>"